window.opener HELP!!

  • Thread starter ctrl+alt+delete
  • Start date
C

ctrl+alt+delete

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!!
 
D

Dietmar Meier

ctrl+alt+delete said:
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
 
C

ctrl+alt+delete

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

Dietmar Meier said:
ctrl+alt+delete said:
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
 
C

ctrl+alt+delete

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 said:
ctrl+alt+delete said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top