Noa wrote:
> I have a page that looks like that:
>
> <form name="kuku1" action ="anotherpage.html" >
> <input name="name">
> <input name="kuku2">
> </form>
>
> As far as i know, "getAttribute" should return a string value of an
> elements' attribute.
>
> document.forms[0].getAttribute("action") indeed returns the string
> "anotherpage.html"
> document.forms[0].action will also return that string
>
> However, document.forms[0].getAttribute("name") does not return the
> string "kuku1", but it returns the first input object.
To be exact, a reference to the first (HTML)Input(Element) object.
> In a similar way , document.forms[0].getAttribute("kuku2") returns the
> second input element, and not a null object (or an empty string) as i
> would expect.
The `null' value and the empty string are very different things. You should
not expect that a value of `object' type like `null' is returned where a
string is specified, as it is here.
> Is it a bug?
Yes, indeed you have discovered another bug in an Element::getAttribute()
implementation, and you provided another reason why it should not be used
in the HTML DOM and why direct property accesses should be used instead,
until further notice.
> is it a defined behavoiur?
No, it is not. Element::getAttribute() is designed to return the value
of the attribute of the element that is represented by the respective
Element object in the DOM. That would the the HTMLFormElement object
representing the `form' element here.
> And how can i get the name of the form ???
Do not name any form control "name", to be exact never use an identifier
of an attribute of `form' elements or a property of (HTML)Form(Element)
objects as name or ID of a form control (if it is child of a `form'
element). However, it is unlikely that you need the name of the form or
need to name the form in the first place; try to use the `this' reference
instead.
PointedEars
Received on Tue Feb 7 21:23:18 2006