I want to use the indeterminate property of a checkbox. Changing the value in JavaScript works in all sorts of browsers (even MSIE6!), however, I cannot set the initial value via HTML attributes in any.
Is this by design? If so, why? On server side, I can determine that it's indeterminate. So, why can't I tell the browser? Weren't browser vendors worried about FOUCs (Flashes Of Unstyled Content) if a long-running script holds up the property-setting?
Here's a working example: http://jsfiddle.net/KUQC9/1/
You can't make a checkbox indeterminate through HTML by design. See this article on css-tricks.com, which discusses the topic in depth.
As for the "why" part of your question, there is some information on the W3C mailing lists that may be helpful:
indeterminate
HTML "content" attribute, as you show in your example, that I could find was here:
For what it's worth, there is in fact an :indeterminate
CSS selector (it seems to be treated like other CSS pseudo-classes like :visited
, which also cannot be set through HTML directly, so maybe that is another reason indeterminate
can't be either). In its demo of the CSS selector the W3C itself uses about the same approach that you do: W3C indeterminate CSS selector demo. In light of that, I'd say you're using about the best method available for setting the indeterminate state of a check box
It is by design. The only HTML way to denote checkbox state is through the checked attribute; this is because checkbox is meant to true/false, rather than true/false/unknown. Marking something indeterminate can be done via Javascript, but it will not change the actual/sumbitted value of the checkbox.
If you really want to initialize checkboxes to indeterminate, you'll need to do it with Javascript (I would imagine on the load event).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With