triple state radio buttons

Can I coax a pair of radio buttons to consistently maintain their
triple state functionality (null, true, false)?

In others words allow the user to undo a response and return the
control to a null state (nothing selected).

I hope this isn't coming down to some sort of Javascript workaround.

Thanks much.

Can I coax a pair of radio buttons to consistently maintain their
triple state functionality (null, true, false)?

In others words allow the user to undo a response and return the
control to a null state (nothing selected).

I hope this isn't coming down to some sort of Javascript workaround.

I don't think so. radio button parameters are either

... passed with a value (if clicked)
... passed with an empty value or not passed at all (if not clicked)

There's no way to distinguish b/n unclicked (which would be your false I assume) and null.

Why not turn them into drop downs with blank/true/false as values?

Thanks for the reply, Philip.

Dropdown boxes are cumbersome visually and ergonomically for the user
and I would rather not go there.

If I have a pair of grouped Ruby generated radio buttons, then
following are the initial possibilities or states:

false - false (in which case presumably a null is returned)
false - true (returns a 0)
true - false (returns a non-zero)

It appears that some ivory towered radio button designer never
conceived that a user might click on a radio button group, change
their mind and want to undo the click therefore returning to a false-
false state. Some languages providing for a user interface have
caught on, some haven't.

Is it perhaps possible to do this by grouping a couple of checkboxes
and set then them up so that the user can select either one or none??

Thanks again,

Quoting the HTML 4 spec:

If no radio button in a set sharing the same control name is initially "on",
user agent behavior for choosing which control is initially "on" is undefined.
Note. Since existing implementations handle this case differently, the
current specification differs from RFC 1866 ([RFC1866] section,
which states:

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

Since user agent behavior differs, authors should ensure that in each
set of radio buttons that one is initially "on".

If you want a "no preference" option, you should provide one explicitly.


As the previous poster said, provide a "Neither" or "None" option and
have that one be selected as the default when the page loads.
That is much easier for a user to understand as well.

I appreciate the answers and help.

So I added a third radio button to the group. Remember that what I
need is a three state situation (null, true, false). This of course
effectively gives me a quadruple state. So I set the third radio
button's value to NIL which gets me back to a three state situation..

Now let me provide a little background.
This is being used for a lengthy questionnaire (there are 50+ sets of
questions). In short, part of good questionnaire design requires that
the design doesn't bias the respondant to particular answers.

So I don't want the radio button group to show a default value. It
potentially confuses respondants and may bias their input. However
with the above configuration (the third radio button value of NIL),
this becomes the default value and is diplayed to user as checked .
Is there a way to avoid this. If I am going to use a three button
group configuration, I need to have them all unchecked initially.


What if you have the third/null value hidden? You can use javascript
for a "clear choice" link or something, which would check the 3,
hidden radio button. It could also be the default for new.

You could provide the third button hidden and initially checked. Show it with javascript
when one of the other buttons is checked so that the user then has the option of selecting it again. You could then make it disapear again when selected if you wanted to.


And as the W3C spec I quoted indicates, you *can't count on that*
if you're using HTML. Period. If none are explicitly checked by you,
the user agent can check any one it wants as a default. Adding a
third button doesn't change that.

Perhaps you should explore using something like Flash/Flex for
your interface?

Hi Hassan,

Do you have any idea of what behavior to expect if I explicitly set
each radio button's checked property to unchecked? What will take
precedence according to W3C specs (or is this all just another browser
war casualty)?

    <%= f.radio_button(:hypotonic_saline, nil, :checked =>
"unchecked") %>

Thanks, Bill

Again, it's up to the user-agent how it handles this situation. I'd just
suggest 1) either accepting having a visible "no preference" choice
(and make it visually obvious that it's a default) or 2) trying what you
suggest and testing thoroughly in all the "standard" browsers.

You'll have to decide how long that #2 list is for your audience :slight_smile:


Why not provide an "Clear" button that deselects all the radio buttons
in the group? That's simple Javascript, and I wouldn't call it a
"workaround". It explicitly provides the functionality that you appear
to want -- a mechanism for a user to undo a response. Seems like a
much simpler and more deft solution to the problem than trying to
rejigger the semantics of radio buttons.

Hmmm... I can use a Javascript solution and assume/hope the worlds'
browsers are all JS enabled. Or use a non-JS solution and assume/hope
the browsers/versions I don't test for will see things the same way.
Either way I don't see things degrading nicely.

My bias (rational or otherwise) is against Javascript. But if I
throw in the towel and go that direction, then I think I would
consider creating some sort of checkbox group and use JS to make sure
that only one checkbox per group could be selected.

Cheers, Bill

A final THANK YOU to all the good folks who took time to reply. Alas,
the suggestions were somewhat unpalatable to me, but at least I am not
still scouring google thinking I have missed some simple alternative.
Sometimes you just can't get there from here.

I have finally gone with the three radio button option with first
one's value set to nil and the entire group explicitely set to
unchecked. So far RFC1866 section hasn't protested about
this breach of propriety and forced a switch in the unchecked status -
at least not in the half dozen browser flavors I've tested so far.