Monday, August 07, 2006

IE Bug Using document.getElementById()

If you are using either document.getElementById() or prototype's $() and you have an element in your page with it's name that is the same as the id of an element that comes after it, DON'T DO IT!!!

IE treats the id and name attributes of elements equally when using document.getElementById().

For an example, use the following HTML code.


<html>
<body>
name: testMe
<input type="text" name="testMe" value="First Element" /><br />
name: dontTestMe id: testMe
<input type="text" name="dontTestMe" id="testMe" value="Second Element" />
<br />
<input type="button" onclick="alert(document.getElementById('testMe').value);" value="Click me to see what happens." " />
</body>
</html>


Working Example


name: testMe


name: dontTestMe id: testMe



No comments: