Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should One HTML Radio Button In a Radio Group Always Be Checked?

Are there any standards (HTML, UI, accessibility, and such like) that stipulate that one of the radio buttons in a given group of radio buttons should be selected at all times?

I have encountered a business requirement whereby I have been asked that both radio buttons in a group be left unchecked, and then to have logic forcing the user to select one before they can continue.

While I know how to achieve this, it felt wrong, and I intimated as such, but was looking for guidelines that stipulate this more explicitly so I can feed this into our own standards.

like image 390
James Wiseman Avatar asked Aug 11 '10 09:08

James Wiseman


People also ask

Are radio buttons checked or selected?

Radio buttons are basically used for the single selection from multiple ones, which is mostly used in GUI forms. You can mark/check only one radio button between two or more radio buttons.

Do radio buttons need to be selected by default?

Always Offer a Default Selection This means enabling people to set a UI control back to its original state. In case of radio buttons this means that radio buttons should always have exactly one option pre-selected. Select the safest and most secure option (to prevent data loss).

How do I keep a radio button checked in HTML?

You can check a radio button by default by adding the checked HTML attribute to the <input> element. You can disable a radio button by adding the disabled HTML attribute to both the <label> and the <input> .


1 Answers

Yes: http://www.w3.org/TR/html401/interact/forms.html#radio

At all times, exactly one of the radio buttons in a set is checked. If none of the elements of a set of radio buttons specifies `CHECKED', then the user agent must check the first radio button of the set initially.

The specification uses the term "user agent" for what is commonly known as "browser". So the specification says that if none is checked, the browser will check the first.

UPDATE: note that none of the 4 Browsers i tried actually does this! They dont check the first and none of the radios are given as =on to the server. A good web framework should do the serverside-checking (it should do it anyway because an abrupted or forged POST could cause the same).

like image 153
matpol Avatar answered Sep 30 '22 12:09

matpol