bharat_ko
asked on
parameter passing from child window to parent window
hi,
my requirment is : I need to click a button on the parent html page. this should open a new child window which has two text fields and two buttons "Ok" and "Cancel".
when i click "Ok" the values in the textfields should be passed to the parent window and stored in two variables.
when i click "Cancel" the window should be closed and the values inthe textfield if any should not be passed
If any one has the idea please post the code.
waiting for reply.
my requirment is : I need to click a button on the parent html page. this should open a new child window which has two text fields and two buttons "Ok" and "Cancel".
when i click "Ok" the values in the textfields should be passed to the parent window and stored in two variables.
when i click "Cancel" the window should be closed and the values inthe textfield if any should not be passed
If any one has the idea please post the code.
waiting for reply.
You should close the window after clicking ok too
<input type="button" name="ok" value="Ok" onclick="passValues();wind ow.close() ;">
Javier
<input type="button" name="ok" value="Ok" onclick="passValues();wind
Javier
true, but he never asked for that ;)
I guess so :c)
ASKER
hi jkna_gunn,
i could not get u with the statment "you will need inputs set up on parent page to pass values back to in above example.".
can u explain what you mean saying "input setup".
i could not get u with the statment "you will need inputs set up on parent page to pass values back to in above example.".
can u explain what you mean saying "input setup".
sorry what i meant was that inorder to pass information back you will need somewhere to pass them back to
for example an input field (most likely).
so in my code i had this
window.opener.document.you rformname. yourinputf ield
so that means on your parent page, you would need a form called yourformname that had an input field called yourinputfield. of course im sure you have these already, so all you need to do is change the names to match your code.
for example an input field (most likely).
so in my code i had this
window.opener.document.you
so that means on your parent page, you would need a form called yourformname that had an input field called yourinputfield. of course im sure you have these already, so all you need to do is change the names to match your code.
ASKER
hi jkna_gunn and jkna_gunn,
can u clearly explain what is "inputs set up on parent page" .
I think i need to stop execution of next statments on parent window till the child window is closed.
can u clearly explain what is "inputs set up on parent page" .
I think i need to stop execution of next statments on parent window till the child window is closed.
ASKER
hi jkna_gunn and jarasa,
can u clearly explain what is "inputs set up on parent page" .
I think i need to stop execution of next statments on parent window till the child window is closed.
can u clearly explain what is "inputs set up on parent page" .
I think i need to stop execution of next statments on parent window till the child window is closed.
Main page -> You have a Form on this page
<Form name=myForm>
<input type=text name=myField1 value="">
</Form>
Child page -> You change the value of a field inside the main page Form
window.opener.document.myF orm.myFiel d1.value = "Hello I write this from the Child Window";
You see now how it works??
Javier
<Form name=myForm>
<input type=text name=myField1 value="">
</Form>
Child page -> You change the value of a field inside the main page Form
window.opener.document.myF
You see now how it works??
Javier
Don't accept my answer, OK? I'm just explaining you jkna_gunn Solution wich it the correct one.
Javier
Javier
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks for your replies.
i am getting a script error.
it says "'ret' is undefined". so i declared 'ret' as
var ret = new Object(); in the child window (i.e) modal dialog.
but still i am getting the same error.
can u tell me why is it so.
one more thing. can i get the reference of my parent window variable or object to the child window (i.e) modal dialog. if it can be done , can you write the code for that
i am getting a script error.
it says "'ret' is undefined". so i declared 'ret' as
var ret = new Object(); in the child window (i.e) modal dialog.
but still i am getting the same error.
can u tell me why is it so.
one more thing. can i get the reference of my parent window variable or object to the child window (i.e) modal dialog. if it can be done , can you write the code for that
// parent page
<script language="JavaScript">
function openChild() {
var win = window.open('child.html',' Child','wi dth=400,he ight=275,t oolbar=yes ,scrollbar s=yes,resi zeable=yes ,menubar=y es,locatio n=yes,stat us=yes');
}
</script>
<form name="parentForm">
<input type="text" name="textField1" value="r">
<input type="text" name="textField2" value="r"><br />
<input type="button" name="openchild" value="Open Child" onClick="openChild()">
</form>
// child page
<script language="JavaScript">
function passValues()
{
window.opener.document.par entForm.te xtField1.v alue = document.childForm.textFie ld1.value;
window.opener.document.par entForm.te xtField2.v alue = document.childForm.textFie ld2.value;
}
</script>
<form name="childForm">
<input type="text" name="textField1" value="">
<input type="text" name="textField2" value=""><br />
<input type="button" name="ok" value="OK" onClick="passValues();">
<input type="button" name="cancel" value="Cancel" onClick="window.close();">
</form>
<script language="JavaScript">
function openChild() {
var win = window.open('child.html','
}
</script>
<form name="parentForm">
<input type="text" name="textField1" value="r">
<input type="text" name="textField2" value="r"><br />
<input type="button" name="openchild" value="Open Child" onClick="openChild()">
</form>
// child page
<script language="JavaScript">
function passValues()
{
window.opener.document.par
window.opener.document.par
}
</script>
<form name="childForm">
<input type="text" name="textField1" value="">
<input type="text" name="textField2" value=""><br />
<input type="button" name="ok" value="OK" onClick="passValues();">
<input type="button" name="cancel" value="Cancel" onClick="window.close();">
</form>
I have tried to alter this last piece of code using radio buttons...but it seems to ignore whether or not the radio buttons are checked or not, so does not pass the values....or rather returns a value of 'undefined'.
As I am not a Javascript whizz....could someone alter the above code to enable a child window to pass through the value of a checked radio button value to one textfield.
This would greatly be appreciated.
As I am not a Javascript whizz....could someone alter the above code to enable a child window to pass through the value of a checked radio button value to one textfield.
This would greatly be appreciated.
<input type="button" name="ok" value="Ok" onclick="passValues()">
<input type="button" name="cancel" value="cancel" onClick="window.close();">
<script language="JavaScript">
function passValues()
{
// pass variable back to parent window
window.opener.document.you
}
</script>
you will need inputs set up on parent page to pass values back to in above example.