DIZZIEDAZZ said:
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