Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML - Why isn't indeterminate="indeterminate|true" respected?

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/

like image 790
Olson.dev Avatar asked Feb 20 '12 18:02

Olson.dev


2 Answers

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:

  • It looks as if the idea of giving checkboxes a tri-state value (seemingly checked, unchecked, indeterminate) was considered, but not implemented because of backwards-compatibility issues
    • See this message
    • And the response
  • The only mention of a true indeterminate HTML "content" attribute, as you show in your example, that I could find was here:
    • In this message
    • And the response
    • You might try contacting those involved in that thread for more information

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

like image 104
Drew Gaynor Avatar answered Oct 03 '22 16:10

Drew Gaynor


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

like image 28
devstruck Avatar answered Oct 03 '22 16:10

devstruck