473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 22131
"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",...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.