barakori
asked on
Submitting a form with "opener" as the target
I have an HTML page that displays data. On that form there's a button that opens another HTML (using window.open) that allows the user to change preferences.
The preferences HTML looks like a regular application popup. When the user presses OK, I have a very complicated form, which I want to submit.
My problem - I want the target to be the "main" page - the one that displays the data. I tried using the target property of the form in the popup page, but it doesn't work:
- I can't use "_parent" since the parent of a window created using window.open() is the window itself.
- The same goes for "_top".
- There's no target="_opener" (Using opened I can get from the popup page to the main page).
- I tried having the main page as a frame with a name. Still, having the target of the popup page point to that frame doesn't work.
One final word: I need something to work with IE5+, NN6. Thanks.
The preferences HTML looks like a regular application popup. When the user presses OK, I have a very complicated form, which I want to submit.
My problem - I want the target to be the "main" page - the one that displays the data. I tried using the target property of the form in the popup page, but it doesn't work:
- I can't use "_parent" since the parent of a window created using window.open() is the window itself.
- The same goes for "_top".
- There's no target="_opener" (Using opened I can get from the popup page to the main page).
- I tried having the main page as a frame with a name. Still, having the target of the popup page point to that frame doesn't work.
One final word: I need something to work with IE5+, NN6. Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
leveret - Excellent and elegant solution.
Kudos.
Kudos.
barakori,
:-)
:-)
In the main page:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript"><!--
myPopup = '';
function openPopup(url) {
myPopup = window.open(url,'popupWind
if (!myPopup.opener)
myPopup.opener = self;
}
//--></SCRIPT>
</HEAD>
<BODY>
<FORM>
<INPUT TYPE="BUTTON" VALUE="Open Popup" onClick="openPopup('popupP
</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
opener.document.hiddenForm
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>
http://developer.irt.org/script/338.htm