Search code examples
htmlradio-buttonxhtml

XHTML-radio button: what's the 'false' value?


I just tried the following HTML :

<input type='radio' checked='checked' name='test' id='r1' />
<input type='radio' checked='' name='test' id='r2' />

which (in my mind's eye) should have the first radio button checked. Turns out browsers will check any radio button with a checked attribute.

Is there a 'false' value, that won't check the button, so my code is consistent?


Solution

  • The absence of the checked attribute is the only way you can do this.

    Traditionally only the word checked was requried to indicate a checked status (you didn't have to set it to be a value). I think the attributename="value" pattern is for compatibility with standards such as xhtml (which is why browsers ignore the value itself)