This came as a surprise to me but I have a simple form with 3 fields in it. The fields dont have a "name" attribute to it. They instead have an "id" attribute.
However. I can still do a
var f = document.getElementsByTagName('form')[0];
alert(f.elementID);
to access the element. I thought to access form elements in that way, the "name" attribute is necessary.
I couldn't find any explanation somewhere for such a behavior. Any pointers ?
EDIT:
I think there is some confusion regarding my question.
my form fields dont have a "name" attribute. They have an "id". Still, I can do this :
myform.elementId
to access them.The question has nothing to do with getElementsByTagName.
getElementsByTagNamefunction because people seem to think that's where your confusion lies. Just put in your examplemyform.fooor something and ask whyfooworks even when it's not a 'name'.