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

Setting variables in another window

P: n/a
Hi,

I'm trying to create specific pop'up window (for product category
selection), but in JS I'm a newbie
and some problem occured, so I have a question:

Is it possible in main window (that opens a popup) to set in popup window:
1. global variables
2. form fields

For example, I'm opening popup window like below:
categories=window.open(address,"categories","scrol lbars=no,height=400,width=
600");

Then I try to set global variable in popup window:
categories.global_variable = 1; //no effect

Or try to set form field:
categories.document.some_form.some_filed.value = "some value"; //no effect

If none of above won't work, how could I pass some data to another window
using JS?

Greets
adeon

Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"adeon" <ad***@tlen.pl> writes:
Is it possible in main window (that opens a popup) to set in popup window:
1. global variables
2. form fields
Yes.
For example, I'm opening popup window like below:
categories=window.open(address,"categories","scrol lbars=no,height=400,width=
600");

Then I try to set global variable in popup window:
categories.global_variable = 1; //no effect

Or try to set form field:
categories.document.some_form.some_filed.value = "some value"; //no effect
You have to wait for the page in the popup window to load.
If none of above won't work, how could I pass some data to another window
using JS?


You are doing it correctly, but it only works when the page is loaded
(or at least has loaded to the point where the form and form field
exists).

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a
Lasse Reichstein Nielsen wrote:
You are doing it correctly, but it only works when the page is loaded
(or at least has loaded to the point where the form and form field
exists).


So, how can I check if form field has been already loaded?
--
Greets
adeon
Jul 20 '05 #3

P: n/a
Adam Dyga wrote:
Lasse Reichstein Nielsen wrote:
You are doing it correctly, but it only works when the page is loaded
(or at least has loaded to the point where the form and form field
exists).


So, how can I check if form field has been already loaded?


To be sure:

if (referenceToWindow
&& !referenceToWindow.closed
&& referenceToWindow.document
&& referenceToWindow.document.forms
&& referenceToWindow.document.forms["foo"]
&& referenceToWindow.document.forms["foo"].elements
&& referenceToWindow.document.forms["foo"].elements["bar"]
&& typeof
referenceToWindow.document.forms["foo"].elements["bar"].value !=
"undefined")
{
/*
* do something with
* referenceToWindow.document.forms["foo"].elements["bar"].value
*/
}

Untested, HTH.
PointedEars
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.