big IE bug.. or am I crazy?
Code Snippet
<html>
<head>
<title>IE BUG!!!!!!</title>
<script language='JavaScript'>
function test(){
alert(window.document.getElementById('el666').getAttribute('value'));
}
</script>
</head>
<body>
<input type="text" id="el888" name="el666" value="input 1" />
<input type="text" id="el666" name="el777" value="input 2" />
<input type="button" value="GO" onclick="JavaScript:test();" />
</body>
</html>
the result of the "alert" shoud be "input 2", but IE shows "input 1" ?!?!?
How can this be?
Firefox run it well!
When I use the method "getElementById", I want to get the element that as that ID.. not that NAME!
Can anyone explain this to me? Am I crazy or what?
[1133 byte] By [
RuiM] at [2008-1-10]
Yes, confirmed.
This is a well known, long standing bug (since IE implemented the ECMAScript .getElementById( ID ) method.
We have (all developers) been waiting for the IE Team to speak up on how/when they plan to fix this so that it follows not only the spec, but the actual name of the method itself.
As for the other reply in this thread, the problem is that other non-input elements can have a name, and thus you can get collisions.
If any of your anchor tags, meta tags, object tags, frame/iframe tags have a matching name value, THEY WILL BE RETURNED FIRST!... which is a MAJOR BUG!
Stay tuned to the IE Blog for more info.
Thank you for your reply.
it's a valid workaround, but in complex and big pages with many elements, it can be a little slow.
I hope that MS correct this in a near future. Is it realy so hard to fix this? I think not!
Rui