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

Get value from popup window to parent window

P: n/a
I have a website which has a popup window (this only opens when the user
chooses to open it). In the popup window I have a <select> control which
lists a selection of "classes". Each class has a description and a class_id
(stored in the value attribute of each option). The user will then select a
class from the drop-down list.

What I want to do is have a control in the parent browser window which can
store the class_id and the description that the user has selected in the
popup window.

Any suggestions as to what control I should use in the parent window and
more importantly how I get the value from the popup window (this must be
client side code as the user will have entered other values into the form in
the parent browser window)?

TIA
Sep 6 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Davey" <da***@hello.com> wrote in message news:43**********@x-privat.org...
I have a website which has a popup window (this only opens when the user
chooses to open it). In the popup window I have a <select> control which
lists a selection of "classes". Each class has a description and a class_id
(stored in the value attribute of each option). The user will then select a
class from the drop-down list.

What I want to do is have a control in the parent browser window which can
store the class_id and the description that the user has selected in the
popup window.

Any suggestions as to what control I should use in the parent window and
more importantly how I get the value from the popup window (this must be
client side code as the user will have entered other values into the form
in the parent browser window)?


The "opener" property of the popup window is a reference to, well, the
opener. ;^) It links the window which opened the popup.

So you might, to populate a form field in the main window, say (from memory
so I may be a bit off):

window.opener.forms.MainForm.SelectedClass.value = "Whatever they pick";

If you have a variable called "CurrentClass" in the main window you can
populate it from the popup like:

window.opener.CurrentClass = "whuddeva";

"opener" is a top-level element: if your popup or your main caller uses
frames then it might get more complicated (you'd have to chain the reference
out further)... but it's still definitely doable.

Good luck!

Jim Davis
Sep 6 '05 #2

P: n/a
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uK*************@TK2MSFTNGP11.phx.gbl...
Davey wrote:
I have a website which has a popup window (this only opens when the
user chooses to open it). In the popup window I have a <select>
control which lists a selection of "classes". Each class has a
description and a class_id (stored in the value attribute of each
option). The user will then select a class from the drop-down list.

What I want to do is have a control in the parent browser window
which can store the class_id and the description that the user has
selected in the popup window.

Any suggestions as to what control I should use in the parent window
and more importantly how I get the value from the popup window (this
must be client side code as the user will have entered other values
into the form in the parent browser window)?
This has nothing to do with ASP (you coulc be doing all of this with two
.htm pages, so it's not an asp issue). You should follow up in a
client-side
scripting newsgroup such as m.p.scripting.jscript.

The specific answer depends on how you are generating the popup window
(openModalDialog? open?).


To be perfectly honest, I'm very rusty with client-side JavaScript. I'm not
even sure how I am going to open the popup, but I vaguely remember
previously generating a pop-up window (three years ago, the last time I had
to do it) in a fairly 'manual' way e.g. manually altering the window
properties.
In general, most of these functions return a
handle to the window that is being opened. You can use that handle to
refer
to objects in the new window. The new window will also have a reference to
the parent window, either via an argument in the function used by the
parent
window to open it, or via its parentWindow property.

The idea is to create what's called a "callback" function in the parent
window. This function can be called by an event procedure (perhaps a
button's onclick event) in the child window. When called it can use the
handle returned by the function used to open the child window to enable it
to read the properties of any controls in the child window and do whatever
you want with them.
This sounds very interesting but would it work even though the user will be
filtering the contents of the popup window once it's open (i.e. getting
filtered data from the db server) - will the popup/function hold its state?
The answer to the first question (what control to use in the parent
window)
depends on the use to which you want to put the values from the child
form.
Maybe a control isn't even needed, as global variables can be used.
The content of the child/popup window will be a form which will allow users
to filter for classes (because there could be thousands of them if left
unfiltered), and a form which will have a drop-down-box with classes in them
(i.e. the results of the filter). It is the value of this combo that I want
returned to the parent window using client side scripting.
Again, follow up in a client-side newsgroup. If you reply to this, please
remove the asp groups from the crosspost.
OK, thanks for the response.
Bob Barrows
PS. since they are not on the msnews server, I cannot reply to the
alt.html
or comp.lang groups in the crosspost, so I am leaving the asp groups in
this
post.

Sep 6 '05 #3

P: n/a
"Jim Davis" <ne********@vboston.com> wrote in message
news:df*********@news2.newsguy.com...
"Davey" <da***@hello.com> wrote in message
news:43**********@x-privat.org...
I have a website which has a popup window (this only opens when the user
chooses to open it). In the popup window I have a <select> control which
lists a selection of "classes". Each class has a description and a
class_id (stored in the value attribute of each option). The user will
then select a class from the drop-down list.

What I want to do is have a control in the parent browser window which
can store the class_id and the description that the user has selected in
the popup window.

Any suggestions as to what control I should use in the parent window and
more importantly how I get the value from the popup window (this must be
client side code as the user will have entered other values into the form
in the parent browser window)?
The "opener" property of the popup window is a reference to, well, the
opener. ;^) It links the window which opened the popup.


What is the syntax for opening a popup which will allow "opener" to be
accessed from the popup?
So you might, to populate a form field in the main window, say (from
memory so I may be a bit off):

window.opener.forms.MainForm.SelectedClass.value = "Whatever they pick";
Yeah this is definitely the sort of thing I'm looking for.
If you have a variable called "CurrentClass" in the main window you can
populate it from the popup like:
By "variable" do you mean hidden form control?
window.opener.CurrentClass = "whuddeva";

"opener" is a top-level element: if your popup or your main caller uses
frames then it might get more complicated (you'd have to chain the
reference out further)... but it's still definitely doable.


Excellent thanks.
Sep 6 '05 #4

P: n/a
"Davey" <da***@hello.com> wrote in message news:43**********@x-privat.org...
"Jim Davis" <ne********@vboston.com> wrote in message
news:df*********@news2.newsguy.com...
"Davey" <da***@hello.com> wrote in message
news:43**********@x-privat.org... The "opener" property of the popup window is a reference to, well, the
opener. ;^) It links the window which opened the popup.


What is the syntax for opening a popup which will allow "opener" to be
accessed from the popup?


There isn't any - "opener" is a standard property - it's automatically
populated for any popup.
If you have a variable called "CurrentClass" in the main window you can
populate it from the popup like:


By "variable" do you mean hidden form control?


Nope - any variable. If, on your main page, you did:

CurrentClass = "SomeStringILike";

You could change that value later from the popup by doing

window.opener.CurrentClass = "SomeNewStringILike";

(Actually you can probably just use "opener" without the "window" but I'm
not sure - I tend to be more specific than JavaScript requires.)

"opener" is just a reference to the window object of the main window (well -
the window that opened the popup) - you can do pretty much ANYTHING you
might do in the main window from the popup using it.

If you want to run a function form the main window you'd use
"opener.myFunction();" for example. If you wanted to see the title of the
opener you'd use "opener.document.title" and so forth. It's all there and
available.

Jim Davis
Sep 6 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.