Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / JScript / March 2005

Tip: Looking for answers? Try searching our database.

Can't find element in javascript

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
clsmith66 - 22 Mar 2005 19:52 GMT
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
Bruce Barker - 23 Mar 2005 00:22 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.