Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Perry Terrance
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64975
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you mean HTMLFormElement.item(0) or HTMLFormElement.item[0]
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show some code.

Eric
 
Perry Terrance
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:Show some code.

Eric


myForm = HTMLFormElement

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are Bear mentioned, it should be () and not square brackets. It is a method on the DOM HTMLCollection.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic