473,395 Members | 1,692 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,395 software developers and data experts.

how to passing value from popup to the parent window as a variable

123 100+
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", after the popup
closed, then from parent window, we can use alert(var_from_popup) and
it will show us the "abc"?
Jan 14 '09 #1
10 11751
acoder
16,027 Expert Mod 8TB
Use window.opener to refer to the parent, then you can set whatever variable you wish in the parent window.
Jan 14 '09 #2
perhapscwk
123 100+
there is a variable var varwindow in primary window;

from popup, i set
window.opener.varwindow="abc"

then from primary window , i use alert(varwindow) but
it write as "underfinded" but not "abc"..why?
Jan 15 '09 #3
Dormilich
8,658 Expert Mod 8TB
try
Expand|Select|Wrap|Line Numbers
  1. alert(window.varwindow);
regards
Jan 15 '09 #4
perhapscwk
123 100+
not okay..why? it still show underfine..


from Mainpage.htm
Expand|Select|Wrap|Line Numbers
  1.  
  2. var item1;
  3. window.open("popup.htm", "name", "width=255,height=455");
  4. alert(item1);
  5.  
from popup.htm
Expand|Select|Wrap|Line Numbers
  1.  
  2. <script type="text/javascript">
  3.  
  4. function get_value()
  5. {
  6.    window.opener.item1="123";
  7. }
  8. </script>
  9. <form>
  10. <textarea name='itembox' rows=10 cols=30></textarea>
  11. <input type="button" onclick="get_value();window.close()" value="Submit">
  12. </form>
  13.  
Jan 15 '09 #5
Dormilich
8,658 Expert Mod 8TB
@perhapscwk
you are mistaking properties with variables. try the code I posted.
Jan 15 '09 #6
perhapscwk
123 100+
I try alert(window.item1) but still not okay..
Jan 15 '09 #7
acoder
16,027 Expert Mod 8TB
It's going to be undefined because there simply isn't enough time before you alert it. When you call window.open, it's more or less asynchronous and moves onto the next line (the alert) without waiting for the window to load. You may not notice this as much on faster computers/simple pages. Even if it was synchronous, your code assumes item1 has already been set, but it's set from a button click.
Jan 15 '09 #8
perhapscwk
123 100+
so how to pass back value from popup to primary window?

i use showmodaldialog ...it okay but not work for firefox 2..
Jan 15 '09 #9
acoder
16,027 Expert Mod 8TB
@perhapscwk
That part works. It's just that you're trying to alert it too quickly. If, for example, you use a button to alert it in the parent window and click it after you click the pop-up window button, it should work.

i use showmodaldialog ...it okay but not work for firefox 2..
showModalDialog support was added in Firefox 3. If you want to support older browsers, either use a normal window.open or write your own pseudo-modal dialog.
Jan 15 '09 #10
gits
5,390 Expert Mod 4TB
yes ... in case you use a normal window.open() you need to implement a mechanism that 'synchronizes' those async operations you trigger. how to do that best, depends a bit on your needs, or better, needed flow of your code.

kind regards
Jan 15 '09 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: veganeater | last post by:
Hi Everyone, I was wondering if there was a way to pass a variable to a popup window. The purpose is make it so when a user clicks on a specific region/link of the glossary page, a popup opens...
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...
15
by: H00ner | last post by:
Hello All Hope you can help Been pulling my hair out about a popup problem in ASP.NET. One of the forms i wrote requires the user to select a product from a list in a popup web form. the...
3
by: Aaron | last post by:
I am having a little difficulty with a relatively simple task. I have a parent webform. I have a javascript attribute added to a button to open a new window when clicked. The user fills in 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"...
3
by: michael | last post by:
let me keep it clean, quick and simple. I am passing a variable into another window and am reassigning the value on the new page - window.document...value = opener.document. ....value and...
7
by: Cordouan | last post by:
I know this looks like it has been answered 1000 times but I have a slightly different problem. I am dealing with forms in order to populate a database. 2 windows : -Main window with my main...
1
by: pingalkar | last post by:
Hi, In my application, I call one popup winodow by using this link.. <a href="#" onClick="return showWindow('1','XYZ');"> <img src="images/magnifier.gif" ALT="Chemicals"...
12
meenakshia
by: meenakshia | last post by:
hi forum i have read a lot of articles regarding passing data from popup to parent up but i m looking for the opposite that is from parent to popup window pls help me in this regard i have...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...

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.