By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,256 Members | 1,700 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,256 IT Pros & Developers. It's quick & easy.

window.opener HELP!!

P: n/a
I have a normal window cotaining a form (named form1). The form has a text
input called imageURL. There is a button that, when clicked, opens a new
window that contains three frames (left, right and bottom.) In the right
frame is another form (named form2) with a hidden input (selected). When
form2 is submitted, I want the value of selected to be passed back to the
imageURL on form1 and then close.

The code I have tried is as follows:

(From my frame...)
<SCRIPT language="JavaScript">
function passValues()
{
// pass variable back to parent window
window.opener.document.form1.imageURL.value =
document.form2.selected.value;
}
top.window.close();
</SCRIPT>

It closes just fine, but imageURL on form1 never changes.

Anyone with ideas on how to make this work is encouraged to offer their
help!!
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
ctrl+alt+delete wrote:
In the right frame is another form (named form2) with a
hidden input (selected). When form2 is submitted, I want the value of
selected to be passed back to the imageURL on form1 and then close.
[...]
// pass variable back to parent window
window.opener.document.form1.imageURL.value =
document.form2.selected.value;


The opener opened the frameset's top window, not the frame your statement
is in. So you want to use top.opener... instead of window.opener... here.
In addition, since the popup is not modal, you should avoid error
messages caused by an already closed opener window (or by having another
document in the opener already) by testing if the used properties and
objects are still available:

var oOpener, oOpenerForm, oOpenerElement;
if (
(oOpener = top.opener)
&& !oOpener.closed
&& (oOpenerForm = top.opener.document.forms["form1"])
&& (oOpenerElement = oOpenerForm.elements["imageURL"])
) {
oOpenerElement.value
= document.forms["form2"].elements["selected"].value;
}

This looks a little laborious compared to waht you had, but it's
essential to avoid error messages.

ciao, dhgm
Jul 23 '05 #2

P: n/a
Hey, thanks a lot for the quick reply! I will try out what you suggested and
post my results.

"Dietmar Meier" <us***************@innoline-systemtechnik.de> wrote in
message news:36*************@individual.net...
ctrl+alt+delete wrote:
In the right frame is another form (named form2) with a
hidden input (selected). When form2 is submitted, I want the value of
selected to be passed back to the imageURL on form1 and then close.
[...]
// pass variable back to parent window
window.opener.document.form1.imageURL.value =
document.form2.selected.value;


The opener opened the frameset's top window, not the frame your statement
is in. So you want to use top.opener... instead of window.opener... here.
In addition, since the popup is not modal, you should avoid error
messages caused by an already closed opener window (or by having another
document in the opener already) by testing if the used properties and
objects are still available:

var oOpener, oOpenerForm, oOpenerElement;
if (
(oOpener = top.opener)
&& !oOpener.closed
&& (oOpenerForm = top.opener.document.forms["form1"])
&& (oOpenerElement = oOpenerForm.elements["imageURL"])
) {
oOpenerElement.value
= document.forms["form2"].elements["selected"].value;
}

This looks a little laborious compared to waht you had, but it's
essential to avoid error messages.

ciao, dhgm

Jul 23 '05 #3

P: n/a
Here's what I ended up going with and it works perfectly:

top.window.opener.document.forms["form1"].elements["imageURL"].value =
"#Form.selected#";

Note: I am processing this script on a ColdFusion page, hence the use of
#Form.selected#.

Thanks again for the help. I wasn't sure how to reference the input back on
my original page.
"Dietmar Meier" <us***************@innoline-systemtechnik.de> wrote in
message news:36*************@individual.net...
ctrl+alt+delete wrote:
In the right frame is another form (named form2) with a
hidden input (selected). When form2 is submitted, I want the value of
selected to be passed back to the imageURL on form1 and then close.
[...]
// pass variable back to parent window
window.opener.document.form1.imageURL.value =
document.form2.selected.value;


The opener opened the frameset's top window, not the frame your statement
is in. So you want to use top.opener... instead of window.opener... here.
In addition, since the popup is not modal, you should avoid error
messages caused by an already closed opener window (or by having another
document in the opener already) by testing if the used properties and
objects are still available:

var oOpener, oOpenerForm, oOpenerElement;
if (
(oOpener = top.opener)
&& !oOpener.closed
&& (oOpenerForm = top.opener.document.forms["form1"])
&& (oOpenerElement = oOpenerForm.elements["imageURL"])
) {
oOpenerElement.value
= document.forms["form2"].elements["selected"].value;
}

This looks a little laborious compared to waht you had, but it's
essential to avoid error messages.

ciao, dhgm

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.