473,387 Members | 1,534 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.

Passing a reference to the popup window

Is there a way, I could pass the reference to a pop up window to
another function?

Basically, this is what I want to
var win= window.open("x.htm".....)

SetValue(win,"txtName");

//-------------------------------------------
function SetValue (win, ctlID)
{
var obj=win.getElementByID(ctlID);
ctlID.value="Hi";
}
I am getting errors when I do this. Any help is appreciated. Thanks
_GJK

Nov 23 '05 #1
1 1881
DIZZIEDAZZ wrote:
Is there a way, I could pass the reference to a pop up window to
another function?
Of course there is.
Basically, this is what I want to
var win= window.open("x.htm".....)

SetValue(win,"txtName");

//-------------------------------------------
function SetValue (win, ctlID)
Consider using a lowercase character for first character of the function
identifier. It helps to tell simple functions and those designed to serve
as constructors apart, and is thus considered a Good Thing regarding code
style.
{
var obj=win.getElementByID(ctlID);
ctlID.value="Hi";
`ctlID' is a string, not the object reference you tried to retrieve.
}
I am getting errors when I do this. [...]


"Does not work" is a useless error description. [psf 4.11]
See <http://jibbering.com/faq/#FAQ4_43>.

getElementById() -- notice the case -- is a method of Document objects,
not of Window objects. Try

var obj = win.document.getElementById(ctlID);
if (obj && typeof obj.value != "undefined")
{
obj.value = "Hi";
}

See also

<http://www.quirksmode.org/js/support.html>
<http://pointedears.de/scripts/test/whatami>

for required feature tests (an example was given above).

However, since you are trying to assign something to the `value' property
in the process, I assume you are trying to modify the value of a form
control. You should not use getElementById() in that case as it requires
W3C DOM Level 2 Support and is probably slower than the alternative.

Consider making it a child element of a `form' element; this would allow
you to refer to the form control by

win.document.forms[...].elements[ctlID]

where `...' would either be the 0-based index or the name string of the
`form' element. Most of this referencing (after document) is specified
in W3C DOM Level 2 HTML, however it is also backwards compliant.
HTH

PointedEars
Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: N/A | last post by:
Hey all, If I open a popup like this window.open('http://www.google.com', 'popup', 'width = 618, height = 425, directories = no, location = no, menubar = no, resizable = no, scrollbars = yes,...
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...
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...
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...
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
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?
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
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...

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.