473,387 Members | 3,787 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,387 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 10474
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?). 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.

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.

Again, follow up in a client-side newsgroup. If you reply to this, please
remove the asp groups from the crosspost.

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.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Sep 6 '05 #2
"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 #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...
11
by: Patricio | last post by:
Hello all I open a PopUp that receives two variables (values). This PopUp must return a value as well. How can I retrieve this value? Thanks a lot.
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.