View Full Version : Pass form data from popup back to parent
Gary Williams
09-11-2002, 12:22 PM
I have produced a form that, when some radio buttons are clicked, causes a popup to be displayed with additional questions. I need to pass the data entered on the popup form back to hidden fields in the main form.
I thought I could do this with document.parentformname.element.value but have not had muck success as yet.
I would really appreciate some guidance from any of you geniuses out there.
Regards
Gary
piglet
09-11-2002, 12:31 PM
Hi Gary,
You can access the opener of the popup through....the "opener" object:
onchange="opener.document.forms.formname.hiddenthing.value=this.value"
RadarBob
09-11-2002, 01:28 PM
Create a simple function on the child page that calls a function on the parent page. I'm not sure if the child page can do it all - reference the parent's form elements; but this is how I learned to do it:
The calling function passes the data as parameter(s). Here's how the call might look:
window.opener.passTheSaltPlease (saltShaker);
On the parent page:
function passTheSaltPlease (HCl) {
document.formname.mytextbox.text = HCl;
} // function passTheSaltPlease
Hope this helped
piglet
09-11-2002, 01:40 PM
Hi
There is no problem directly accessing anything on the opening document that you'd access from within that document itsself - for example:
<HTML><BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
window.open("poptest.html")
//-->
</SCRIPT>
</BODY>
<FORM name="formname">
<INPUT TYPE="text" NAME="thing">
</FORM>
</HTML>
this is poptest.html:
<HTML><BODY>
<A HREF="#" onclick="opener.document.formname.thing.value='Blah'; return false">Populate Opener</A>
</BODY>
</HTML>
RadarBob
09-11-2002, 08:15 PM
OK, I just discovered that the way I do it is "legacy code." Here's an excerpt from Pure Javascript
In older versions of Javascript, windows could only be referenced from the top down. This meant that a parent window would know the properties of its child windows, but not vice versa. In JavaScript version 1.2 and later, this problem is resolved.
Gary Williams
09-11-2002, 08:56 PM
Thanks Piglet and RadarBob for your quick replies. I've got the pop up sorted and the text passing back from the pop up window to the text field in the opener window.
This is good.
The text(s) I need to pass back however are themselves in text fields in the pop up form. I've tried replacing value = 'blah' with value = 'document.popupform.fieldname.value' but this (and other variations) don't work.
What should I replace 'blah' with?
In the meantiome, I have more reading of tutorials to do.
Thanks again
Gary
RadarBob
09-11-2002, 09:30 PM
OK, G.W., you lost me.
what page is what on? To reference something that's on a window other than the one you're on right now, you must reference that window.
"Window.opener" is a special case for being able to reference the window from which this one (the popup window) was opened - without explicitly referencing it by name.
So, on the popup window code something like this:
window.opener.document.yourFormName.yourTextBoxName.value = blah
Gary Williams
09-11-2002, 11:41 PM
Sorry RadarBob, here is a more complete description:
I have produced a normal html enquiry form that uses text boxes, radio buttons, etc.
When one of the radio buttons is clicked, a popup window is displayed (also a form) that contains additional questions for clarification. The answers are entered into text boxes in the pop up window.
When these answers have been entered and the close pop up window button is clicked, I need the data entered into the text boxes in the pop up window to be copied back into hidden text fields in the main form, ready for submission.
This means that in the previous solutions from yourself and piglet, I need to replace the pre-defined text 'blah' with the values entered into the pop up windows text boxes by the person completing the form.
Ie, window.opener.document.yourFormName.yourTextBoxName.value = 'value entered into the text box(s)'
Regards
Gary
RadarBob
09-12-2002, 01:04 PM
Then I'd think something like this would work, on the popup page:
window.opener.document.yourFormName.yourTextBoxName.value =
document.thisdocFormName.theTextBoxName.value
vBulletin® v3.8.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.