About KJS::HTMLCollection::getNamedItems

Koos Vriezen koos.vriezen at xs4all.nl
Thu Aug 15 12:33:37 BST 2002


On Thu, 15 Aug 2002, David Faure wrote:

> On Thursday 15 August 2002 10:31, Koos Vriezen wrote:
> >
> > Ok, tested on IE 6.0:
> >   <html><body onLoad='alert(""+document.myname.nodeName)'>
> >   <form name="myname">
> >     <input name="myname" type="text">
> >   </form>
> >   </body></html>
> > Message box shows FORM. With document.myname.myname.nodeName it shows
> > INPUT.
> This only proves that the site works, it doesn't explain why/how.
> What does alert(""+document.myname) show?
> And document.myname[0].nodeName, and with [1] ?
> (to see if it behaves as an array AND as a normal element too)
>
> > If I add another form with 'myname' as name, the alert box shows
> > 'undefined', without the 'nodeName' its '[Object]'
> So you get a list of two forms in that case....
>
> > It seems that no collection is returned when child/parent with the same
> > name occur.
> That's a VERY broad statement, which would need further testing with other
> kind of elements.

Blame email. Seems as appears/looks like. Just trying to find some logic.

> - From the above one could also conclude that "document.formname" first looks
> at forms (and returns only forms, if it found any). The reason I'm tempted to
> believe in this "exception" is that document.formname is already an exception:
> we (and IE) look for that before looking for JS properties that have been
> set in the document. What I mean is (with the above <form> tag assumed) :
> document.myname = 'foo';
> alert(document.myname);  << will still return the FORM object, not 'foo'.
> But this only happens with forms and images apparently. The other cases
> of document.myname lookup are done after the JS property lookup.

I think you're right. Did some tests, always come up with FORM.

On this example:
  <html><body onLoad='alert(""+document.myname.length)'>
    <form name="myname">
      <input name="myname" type="text">
  </form></body></html>
=> 1

alert(""+document.myname)
=> [Object]

alert(""+document.myname[0].nodeName)
=> INPUT

document.myname[1].nodeName
=> script error

Regards,

Koos





More information about the kfm-devel mailing list