aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes JavaScript DOM Node-Traversal and the Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JavaScript DOM Node-Traversal and the "Dreaded" Undefined Errors" Watch "JavaScript DOM Node-Traversal and the "Dreaded" Undefined Errors" New topic
Author

JavaScript DOM Node-Traversal and the "Dreaded" Undefined Errors

Perry Terrance
Ranch Hand

Joined: Oct 02, 2009
Posts: 60
Hi All,

I am currently trying to convert some horrendous IE 7-specific JavaScript DOM codes into W3C-compliant DOM JavaScripts... Unfortunately, I've been hitting a lot of brickwalls where I try to translate an IE 7-specific JS-DOM property to a W3C compliant JS-DOM property - only to get the dreaded "undefined" error message in my Safari Error Console.

Take for example the following:

I've been wading through a lot of IE JS-DOM codes that end up giving me what Safari recognizes as HTMLFormElement node object. In Safari's Debug Mode, I see the HTMLFormElement node object is full of blank HTMLInputElement node objects. So I thought I could just do a HTMLFormElement.item(0), HTMLFormElement.item(1), etc... to select each of these HTMLInputElement node objects even though they are shown as blank in the debug window...

However - as soon as my JS hits HTMLFormElement.item(0) - the console says "undefined". Which doesn't make sense - cause HTMLFormElement.length = 100 (so there's definitely child-nodes in there.) At this point, I'm getting kind of lost on what to do, cause Safari is blatantly telling me HTMLFormElement exists - with length of 100, but I can't access even the 0-index item of it...

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61436
    
  67

Did you mean HTMLFormElement.item(0) or HTMLFormElement.item[0]


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Show some code.

Eric
Perry Terrance
Ranch Hand

Joined: Oct 02, 2009
Posts: 60
Eric Pascarello wrote:Show some code.

Eric


myForm = HTMLFormElement

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Are Bear mentioned, it should be () and not square brackets. It is a method on the DOM HTMLCollection.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JavaScript DOM Node-Traversal and the "Dreaded" Undefined Errors