Live life to the fullest

my random thoughts and stories

Posts Tagged ‘IE bug

IE Auto-set ID Attribute

leave a comment »

Recently I stumble upon another glitch with IE. IE is well known as the most unstandard web browser on earth.

Consider this simple HTML code snippet

<input type="hidden" name="input" value="this is a secret message" />
<input type="text" id="input" value="you should see this if you use a sane browser" />
<input type="button" value="click me" onclick="doSomething()" />

<script language="javascript">
var doSomething = function() {
	var elem = document.getElementById('input');
	if (elem) alert(elem.value);

What do you expect to see when you run this? I expect to see an alert box with “you should see this if you use a sane browser” as the message. Apparently in IE you’ll see “this is a secret message”.

What happen exactly is that IE “cleverly” add an ID attribute to our input element (yes it only applies to input element) to be the same value as the NAME attribute. How did they decide this “clever” feature in the first place? Where is it documented? I guess it will remain a mystery to us. Maybe we should start a campaign to Kill IE (there’s already one for IE6

So next time you encounter a problem in IE you might want to check if it’s “IE Auto-set ID Attribute”.

Written by jecki

October 3, 2009 at 3:48 am

Posted in Uncategorized, Work

Tagged with ,