W3C home > Mailing lists > Public > whatwg@whatwg.org > October 2009

[whatwg] 4.10.5 - value of hidden inputs

From: Ian Hickson <ian@hixie.ch>
Date: Mon, 12 Oct 2009 01:44:39 +0000 (UTC)
Message-ID: <Pine.LNX.4.62.0910120114030.25383@hixie.dreamhostps.com>
On Tue, 6 Oct 2009, Kartikaya Gupta wrote:
>
> 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?

It was foo, per the spec.


> 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'.

Fixed the spec.


> 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.

IE does all kinds of weird things with forms. Try getAttribute('defaultValue')...


> 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.

This is now fixed too, as far as I can tell.

Thanks,
-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Sunday, 11 October 2009 18:44:39 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:18 UTC