/    Sign up×
Community /Pin to ProfileBookmark

Problem with PHP + JavaScript

——-Parent window (first.php)
<html>
<head>
<title>Job Profile</title>
<script type=”text/javascript”>

function open_win(){

w = window.open(‘second.php’, null, ‘left = 103, top = 72, width=400,height=300,scrollbars=no,menubar=no,location=no,status=yes,resizable=yes,toolbars=no’);

w.document.supervisorform.txtsupervisor.value = document.jobprofile.txtsupervisor.value;

}

</script>
</head>

<?php

echo ” we are here”;

?>

<BODY>
<FORM name=”jobprofile” method=”POST” action=””>
<TABLE>
<TR>
<TD>
<DIV align=”right”>Supervisor : </div>
</TD>
<TD colspan=”2″>
<input type=”text” name=”txtsupervisor” size=”50″ maxlength=”50″ value=””>
</TD>
<TD colspan=”2″>
<input type=”button” onclick=”open_win();” value=”Browse”>
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>

——– child window (second.php)———-

<HTML>
<HEAD>
<TITLE> AeraSoft – SmartHR </TITLE>
<META NAME=”Generator” CONTENT=”EditPlus”>
<META NAME=”Author” CONTENT=””>
<META NAME=”Keywords” CONTENT=””>
<META NAME=”Description” CONTENT=””>
<SCRIPT LANGUAGE=”JavaScript”>
<!–
window.focus();

function passvariable(){

window.opener.jobprofile.txtsupervisor.value= supervisorform.txtsupervisor.value;

}
//–>
</SCRIPT>
</HEAD>

<BODY>
<FORM name=”supervisorform” METHOD=”POST” ACTION=”” >
<INPUT TYPE=”text” NAME=”txtsupervisor” value=””>
<INPUT TYPE=”button” name=”submit” value=”submit” onclick=”passvariable()”>
</form>
</BODY>
</HTML>


————————————————–

somebody pls try this coding ..

copy and save the first script as first.php
copy and save the second script as second.php

when you enter something in the Parent window and submit,
the value may be appeared in the child window. but if you keep clicking at the submit button, and you notice sometime the value doesn’t been passed into the child window… and sometime it does!

this problem is solved if the php coding in first.php(parent window) is removed..

can someone solve the problem for me?

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@fredmvDec 30.2003 — [font=courier]function passvariable() {

&nbsp;&nbsp;&nbsp;&nbsp;window.opener.jobprofile.txtsupervisor.value = [b][color=red]document.[/color][/b]supervisorform.txtsupervisor.value;

} [/font]
Copy linkTweet thisAlerts:
@ltingauthorDec 30.2003 — emm the one is for child window ..

the problem is i need to pass value from parent to child ..

if i remove any php code .. then everything works fine ..

but if i put some into the parent window ..

when i click submit sometime it passed value to child window, but sometime it doesn't ..

i wonder why ..
Copy linkTweet thisAlerts:
@stoodderDec 30.2003 — hre ya go replace the javascript in the first page with this:

[code=php]
<script type="text/javascript">

var openwin = false;
function open_win(){

if(!openwin) {
try {
newWin = window.open("second.php", null, 'left = 103, top = 72, width=400,height=300,scrollbars=no,menubar=no,location=no,status=yes,resizable=yes,toolbars=no');
openwin = true;
} catch(e) {
openwin = false;
alert("no Win");
}
setTimeout('open_win()',1);
} else {
try {
newWin.document.supervisorform.txtsupervisor.value = document.jobprofile.txtsupervisor.value;
} catch(e) {
openwin = false;
setTimeout('open_win()',1);
}
}
}

</script>
[/code]


tell me if that works for you.
Copy linkTweet thisAlerts:
@ltingauthorDec 30.2003 — hahhaa

finally it works!!!!!!!!!

thanks thanks !!!!


hehehe you make the javacript loop?

heheh until got value inside the child window?
Copy linkTweet thisAlerts:
@fredmvDec 30.2003 — You're welcome. ?
Copy linkTweet thisAlerts:
@stoodderDec 30.2003 — yea cause for some reason it trys to define the form fiel dbefore it loads. lol jeez couldntt they make it easier.
Copy linkTweet thisAlerts:
@ltingauthorDec 30.2003 — emmm b4 i tried that, my window.focus() is working ..

when ever i click submit the child window will appear in front..

now window.focus doesn't work ...
Copy linkTweet thisAlerts:
@horiyochiDec 30.2003 — thanks stoodder

it works for me as well!
Copy linkTweet thisAlerts:
@horiyochiDec 30.2003 — for window focus

var openwin = false;

function open_win(){

if(!openwin) {

try {

newWin = window.open("www.php", null, 'left = 103, top = 72, width=400,height=300,scrollbars=no,menubar=no,location=no,status=yes,resizable=yes,toolbars=no');

openwin = true;

} catch(e) {

openwin = false;

alert("no Win");

}

setTimeout('open_win()',1);

} else {

try {

newWin.document.supervisorform.txtsupervisor.value = document.jobprofile.txtsupervisor.value;

[COLOR=red]newWin.window.focus();[/COLOR]

} catch(e) {

openwin = false;

setTimeout('open_win()',1);

}

}

}
×

Success!

Help @lting spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...