window.opener HELP!! 
July 23rd, 2005, 05:34 PM
| | | window.opener HELP!!
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!! | 
July 23rd, 2005, 05:34 PM
| | | 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 | 
July 23rd, 2005, 05:35 PM
| | | 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] | 
July 23rd, 2005, 05:35 PM
| | | 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] | | Thread Tools | Search this Thread | | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 220,989 network members.
|