Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q339 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, even if the location of the main page has changed?

irt.org | Knowledge Base | JavaScript | Window | Q339 [ previous next ]

Q339 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, even if the location of the main page has changed?

topFrame.html:

<HTML>
<FRAMESET ROWS="100%,*">
<FRAME SRC="visiblePage.html" NAME="visibleFrame">
<FRAME SRC="hiddenPage.html" NAME="hiddenFrame">
</FRAMESET>
</HTML>

visiblePage.html:

<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>
</BODY>
</HTML>

hiddenPage.html:

<HTML>
<BODY>
<FORM NAME="hiddenForm" ACTION="targetPage.html" TARGET="visibleFrame">
<INPUT TYPE="TEXT" NAME="myTextField">
</FORM>
</BODY>
</HTML>

popupPage.html:

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

nextPage.html:

<HTML>
<BODY>
<H1>nextPage.html</H1>
</BODY>
</HTML>

targetPage.html:

<HTML>
<BODY>
<H1>targetPage.html</H1>
<SCRIPT LANGUAGE="JavaScript"><!--
document.write('<P>Data passed = ' + location.search);
//--></SCRIPT>
</HTML>

Feedback on 'Q339 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, even if the location of the main page has changed?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.