Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q338 How can I submit a form on a popup window and target the results into the main window and close the popup window at the same time?

You are here: irt.org | FAQ | JavaScript | Window | Q338 [ previous next ]

In the main page:

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript"><!--
myPopup = '';

function openPopup(url) {
    myPopup = window.open(url,'popupWindow','width=640,height=480');
    if (!myPopup.opener)
         myPopup.opener = self;
}
//--></SCRIPT>
</HEAD>
<BODY>
<FORM>
<INPUT TYPE="BUTTON" VALUE="Open Popup" onClick="openPopup('popupPage.html')">
</FORM>

<FORM NAME="hiddenForm" ACTION="nextPage.html">
<INPUT TYPE="HIDDEN" NAME="myTextField">
</FORM>

</BODY>
</HTML>

In the popupPage.html:

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript"><!--
function copyForm() {
    opener.document.hiddenForm.myTextField.value = document.popupForm.myTextField.value;
    opener.document.hiddenForm.submit();
    window.close();
    return false;
}
//--></SCRIPT>
</HEAD>
<BODY>
<FORM NAME="popupForm" onSubmit="return copyForm()">
<INPUT TYPE="TEXT" NAME="myTextField">
<INPUT TYPE="BUTTON" VALUE="Submit" onClick="copyForm()">
</FORM>
</BODY>
</HTML>

Feedback on 'Q338 How can I submit a form on a popup window and target the results into the main window and close the popup window at the same time?'

©2018 Martin Webb