[thelist] validating radio buttons

Jonathan_A_McPherson at rl.gov Jonathan_A_McPherson at rl.gov
Thu Jul 11 17:26:01 CDT 2002


> I've seen this a lot lately. The default for a radio button group is
> that one button is ALWAYS selected - even when the page loads.
> Otherwise you are circumventing the way radio groups work.
>
> The point is to allow 1, and only 1 selection. You are supposed to
> provide a "default" selection, the user changes it if they wish.

It's been my observation that Internet Explorer (yes, I code for a corporate
intranet) does not pre-select a radio button if you do not tell it to. So,
for instance, the below code:

<input type="radio" name="bob" value="alice" />
<input type="radio" name="bob" value="carol" />

will _not_ result in any radio buttons being selected. It will leave both
unchecked. As soon as a user clicks one, however, they've no choice but to
select one of the two; there's no way for them to return to the original
state of the page.

This seems to be an advantage at first, because it allows you to see if the
user made a choice. If you do something like this:

<input type="radio" name="bob" value="alice" checked="checked" />
<input type="radio" name="bob" value="carol" />

then you don't know whether the user really wanted "alice" or whether they
just didn't notice the option.

I propose that this would be the correct way to handle the situation:

<input type="radio" name="bob" value="neither" checked="checked" />
<input type="radio" name="bob" value="alice" />
<input type="radio" name="bob" value="carol" />

This is easy to validate via JavaScript or server-side routines. It works
identically on user agents that do not automatically check the first item in
a radio button group and user agents that do.

For the applications I write, it's important to me to be sure the user
actually intended to make a choice, and if I don't provide some sort of
default choice I can trap for, I can't be sure.

--
Jonathan McPherson, LMIT/SD&I
Software Engineer & Web Systems Analyst
email / jonathan_a_mcpherson at rl dot gov



More information about the thelist mailing list