[whatwg] 4.10.5 - value of hidden inputs

If we have this page:

<html><body>
<input type="hidden" value="foo" id="i">
<script type="text/javascript">
  var i = document.getElementById('i');
  i.value = 'bar';
  alert( i.getAttribute('value') );
</script>
</body></html>

What should the alert display? From my reading of the spec I believe it should display 'foo'. For type=hidden, "The value IDL attribute applies to this element and is in mode value" and in mode value, "On setting, it must set the element's value to the new value, set the element's dirty value flag to true [...]". Reading the content attribute after should still return the original 'foo'.

However, Firefox, Opera, IE6, and Chrome all alert 'bar'.

If I change the type from hidden to text, then FF, Opera, and Chrome all alert 'foo', but IE6 still gives me 'bar'. This, despite both 'hidden' and 'text' are in mode value, and so should behave the same according to the spec.

Another related test case is this one:

<html><body>
<input type="hidden" value="foo" id="i">
<script type="text/javascript">
  var i = document.getElementById('i');
  i.value = 'bar';
  i.removeAttribute('value');
  alert( i.value );
</script>
</body></html>

According to the spec, setting i.value should set the dirty value flag. This means that when the content attribute is removed, it shouldn't affect what i.value returns for the alert. However, Firefox, Opera, and Chrome all alert the empty string. It seems they all have special behavior for type=hidden that isn't specced fully.

Cheers,
kats

Received on Tuesday, 6 October 2009 12:36:05 UTC