Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange behaviour - Foxfire vs IE

Status
Not open for further replies.

bthale

Programmer
Oct 31, 2001
108
US
I ran across a situation I thought was strange and wanted to know if anyone else has seen this.

In Foxfire, document.getElementById("someElem") returns null if this element is a child of <form>. I had to use something like document.myForm.someElem to get the object.

In IE, document.getElementById("someElem") returns an object no matter inside a <form> or not.

Am I crazy or is this by design in Foxfire?
 
On the face of it, the element must have id (strictly id, not any other attribute such as name) "someElem". And, that id must not be collision with other markup's.
 
I agree with tsuji. If 'someElem' is the name of the element and not the ID it would cause issues in Firefox.

IE will erroneously use the name as an Id if no ID is present.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
That's probably it. Most of my elements have 'name' instead of 'id'.

Thanks
 
Technically they should have both. but if you are suing getElementById they should definitely have at least an Id. As that is what you are requesting.

Should you need to access an element by name, there is getElementsByName.

Note that this will return an array with every element that has the specified name.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top