Connecting Tech Pros Worldwide Forums | Help | Site Map

window.opener HELP!!

ctrl+alt+delete
Guest
 
Posts: n/a
#1: Jul 23 '05
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!!



Dietmar Meier
Guest
 
Posts: n/a
#2: Jul 23 '05

re: window.opener HELP!!


ctrl+alt+delete wrote:
[color=blue]
> 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;[/color]

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
ctrl+alt+delete
Guest
 
Posts: n/a
#3: Jul 23 '05

re: window.opener HELP!!


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

"Dietmar Meier" <usereplytoinstead@innoline-systemtechnik.de> wrote in
message news:36h5iqF53jnaoU1@individual.net...[color=blue]
> ctrl+alt+delete wrote:
>[color=green]
>> 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;[/color]
>
> 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[/color]


ctrl+alt+delete
Guest
 
Posts: n/a
#4: Jul 23 '05

re: window.opener HELP!!


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" <usereplytoinstead@innoline-systemtechnik.de> wrote in
message news:36h5iqF53jnaoU1@individual.net...[color=blue]
> ctrl+alt+delete wrote:
>[color=green]
>> 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;[/color]
>
> 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[/color]


Closed Thread