Hopefully someone can help me because I am very confused. I need to write a
javascript function to set the properties on an activeX control I wrote. For
some reason though any javascript I write in my ASP.NET page can't fnd even
the simplest control. Just for test I have the following code:
function Test() {
alert(document.Form1.hdnCustName.value);
}
Every time I run this function it throws an error saying
document.Form1.hdnCustName.value is null or not an object. I've double
checked the control name and even set the value of the control in the html.
Nothing. I get a similar error if I use document.getElementById. Can anyone
help me find what I might be missing? I've used similar and more complex
code in the past and cannot figure out why this piece will not work.
Thanks in advance
Chris Smith
active/x controls are not form elements, and thus are not form children, so
you cannot reference them from the form as you are trying.
try:
myControl = document.getElementById('hdnCustName'); // supply id attribute
on <object tag>
myControl = document.getElementByName('hdnCustName')[0]; // supply name
attribute on <object tag>
also active/x control are loaded async. they can be null until the onload
event fires. properties should not be accessed until readyState == 4, as the
object maynot be created or init until then.
so you normally do something like:
// loop until ready - burns cpu - should use setTimeout
myControl = null;
while (true)
{
myControl = document.getElementById('hdnCustName');
if (myControl && myControl .readyState == 4)
break
}
// can now access control (may never get here)
myControl.prop = ...
-- bruce (sqlwork.com)
> Hopefully someone can help me because I am very confused. I need to write
> a
[quoted text clipped - 17 lines]
> Thanks in advance
> Chris Smith
Serge Baltic - 23 Mar 2005 13:38 GMT
bb> // loop until ready - burns cpu - should use setTimeout
bb> myControl = null;
bb> while (true)
Not should but must; either setTimeout or setINter
(H) Serge