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

3

7

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?

Homeland answered 30/5, 2011 at 6:45 Comment(0)
C
8

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)

Carbarn answered 30/5, 2011 at 6:48 Comment(2)
Yes, <input checked /> looks sloppy and inconsistent. Ah well can't have everything. Thanks for the confirmation.Homeland
The attributename="attributename" form for boolean attributes was part of HTML 2.0 (rfc-editor.org/rfc/rfc1866.txt) - long before XHTML was invented.Riel
M
2

The presence of the checked attribute is generally enough for the browser to have it checked by default.

In a radio control group though, I'd just put the attribute on the initial one selected and omit it on the other radio elements.

Mandibular answered 30/5, 2011 at 6:48 Comment(0)
G
1

There's no false value. If the checkbox is not checked, the browser will not send it via $_GET or $_POST. You should use "value" attribute also - and check on serverside for that value. Otherwise it's false.

Gonzales answered 30/5, 2011 at 6:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.