About KJS::HTMLCollection::getNamedItems

Vadim Plessky lucy-ples at mtu-net.ru
Fri Aug 16 08:13:33 BST 2002


On Thursday 15 August 2002 3:53 pm, David Faure wrote:
|  On Thursday 15 August 2002 13:33, Koos Vriezen wrote:
|
|  > alert(""+document.myname)
|  > => [Object]
|
|  IE isn't very descriptive :}

-------------------------------------------
<html>
<body>
    <form name="myname">
      <input name="myname" type="text">
  </form>
  <script language="JavaScript">
  /* get body element  */
  /* works fine in Konq, but Mozilla return HEAD */
 /*  elbody = document.firstChild.firstChild;  */
 /* get body via different method */
  elbody = document.getElementsByTagName("body")[0];
  document.write("<br>This element should be <Body> "+elbody);

  elbodychild = elbody.firstChild;
  document.write("<br>first child of <Body>= "+elbodychild);

  elform = document.getElementsByTagName("form")[0];
  document.write("<br>This element should be <form> "+elform);
  elformchild = elform.firstChild;
  document.write("<br>first child of <form> "+elformchild);

  elmyname = document.myname;
  document.write("<br>document.myname= "+elmyname);

  </script>
  </body>
  </html>
-------------------------------------------

Mozilla
***
This element should be <Body> [object HTMLBodyElement]
first child of <Body>= [object Text]
This element should be <form> [object HTMLFormElement]
first child of <form> [object Text]
document.myname= [object HTMLFormElement]

Konqueror
***
This element should be <Body> [object BODY]
first child of <Body>= [object Text]
This element should be <form> [object FORM]
first child of <form> [object Text] 

--> document.myname not returning object at all!

BTW: I also wonder *why* Konq and Mozilla return [Text] object as firstChild?
Is this correct (and I miss something), or first child of body should be 
<form> element?

|
|  > alert(""+document.myname[0].nodeName)
|  > => INPUT
|
|  Confusing test/result too ;) That's not "first item called myname", it's
|  "first form element in the myname form". Reason:
|  myname[0] and myname.item(0) are the same, they lead to
|  <object-returned-by-'myname'>::get('0').
|
|  > document.myname[1].nodeName
|  > => script error
|
|  Yes, no second form element.
|
|  But this doesn't answer the "is this behaviour for forms only, or for all
| nested elements". Did you try stuff like <div name='test'><div
| name='test'></div></div>, to see if your idea about identically-named
| nested elements is true?
|
|  I think this is really only for forms. The fix would be to add a new value
| to the ReturnType enum in KJS::HTMLCollection, named "ReturnForm" (i.e.
| only return form elements), and add support for it in HTMLCollection, and
| use that value in kjs_html.cpp:169 if element.elementId() == ID_FORM.
|
|  - --
|  David FAURE, david at mandrakesoft.com, faure at kde.org

-- 

Vadim Plessky
http://kde2.newmail.ru  (English)
33 Window Decorations and 6 Widget Styles for KDE
http://kde2.newmail.ru/kde_themes.html
KDE mini-Themes
http://kde2.newmail.ru/themes/





More information about the kfm-devel mailing list