[thelist] BUG: Broken Value Attribute for BUTTON Element in IE5+

Aylard JA (James) jaylard at equilon.com
Tue Oct 3 16:33:19 CDT 2000


	This may already be public knowledge; also, I posted my discovery of
this IE bug on another list earlier today, so I apologize to any who might
already be aware of this information:
	Internet Explorer 5 and 5.5 have a faulty "value" attribute for the
HTML 4 <button> element. Instead of posting the value of the "value"
attribute, IE5/5.5 post the button's innerHTML value. An example of what
this means:

<button type="submit" 
	value="The real value">The innerHTML value</button>

	When clicked, this will submit "The innerHTML value" as the value of
the button, not "The real value". According to Microsoft's documentation for
its implementation of the <button> element
p), this was the intended behavior for IE4 (although in my tests, IE4
doesn't submit *any* value), but for IE5+, the value of the "value"
attribute, if there is one, should override the innerHTML value. Alas, that
is not the case. As well, you cannot retrieve the value of the "value"
attribute with scripting, either; it also returns the button's innerHTML as
its value.
	I developed a workaround which works for IE5/IE5.5 as well as
Netscape 6 (which doesn't exhibit this problem, but gracefully plays along
with the solution). It involves essentially creating an entirely new "value"
attribute (what is called an "expando" property in Microsoft lingo) using
the W3C DOM's setAttribute method:

<button type="submit"
	value="The real value"
	onclick="this.setAttribute('value','The real value');">The innerHTML

	Of course, the explicit use of the HTML "value" attribute here is
unnecessary, but is still a wise idea.

James Aylard

More information about the thelist mailing list