472,805 Members | 1,070 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

Get value from popup window to parent window

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
4 22062
"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
"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
"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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alex Shinn | last post by:
I have a site which uses popup windows as a convenience in filling out forms - you choose some data on the popup, click OK, and it sets data on the parent windows form. This works fine in all...
3
by: MEM | last post by:
Hello, I'd like to refresh the main or top most browser window from a child window. Specifically, child popup A is opened by a main browser window then child popup B is opened from within child...
1
by: Marshall Dudley | last post by:
I have an application where in a shopping cart checkout a popup appears which suggests other items that may go with what was ordered with a button to add these items to the cart. When the button...
1
by: Bill H | last post by:
I run a dbms application that interfaces with the web. This module creates a frames page with two frames ('main' and 'mwinfoframe'). All communication with the dbms is routed through the...
4
by: Davey | last post by:
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...
1
by: ABC | last post by:
I has a parent and a popup lookup ASP.NET Form. Both has javascript. I test the popup window's window.Form1.SelectedProductCode.value has a value. But don't know why the return variable "retvar"...
5
by: knowdotnet | last post by:
Hi all, Which is the best way to return a value back to the web page from a pop up page? I have a asp.net web application which opens a popup page on a link button click. The Link button is...
4
by: neena | last post by:
Hi I am uing C#.net & using javacript for a popup window. I've a form and there is a button named Categories. When it is clicked, it will open a new window for the selection of categories. When...
10
by: perhapscwk | last post by:
how to passing value from popup to the parent window as a variable which I can access and process the variable(string) in parent window? such as from popup page, we have var_from_popup="abc",...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.