By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,442 Members | 1,302 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,442 IT Pros & Developers. It's quick & easy.

radio button question

P: n/a
I have a simple registration form that needs a binary answer (one or the
other) in several places, using radio buttons. Since at least one radio
button in a group should be checked initially, and I don't want it to
default to either, I am using a third option as the default (checked).
Rather than have that third option say something like "you must pick one
of the other two", I am styling it as hidden like this:

<label style="visibility:hidden">Huh!<input name="Permission"
type="radio" value="Huh!" checked ></label>

Does anyone see any unintended consequences to doing it this way?

I realize that once they check either one of the visible options they
can't get back to the default, but that's really what I want.

Mar 26 '08 #1
Share this Question
Share on Google+
8 Replies


P: n/a
William Gill wrote:
I have a simple registration form that needs a binary answer (one or
the other) in several places, using radio buttons. Since at least
one radio button in a group should be checked initially, and I don't
want it to default to either, I am using a third option as the
default (checked). Rather than have that third option say something
like "you must pick one of the other two", I am styling it as hidden
like this:

<label style="visibility:hidden">Huh!<input name="Permission"
type="radio" value="Huh!" checked ></label>

Does anyone see any unintended consequences to doing it this way?
Yes. You still need to test in the action script.
I realize that once they check either one of the visible options they
can't get back to the default, but that's really what I want.
Why can't you simply use two buttons, with neither hidden and neither
selected as "checked"? Such as:

<input type="radio" name="q1" value="ayup">&nbsp;Yes<br>
<input type="radio" name="q1" value="nope">&nbsp;No

Have your action script test for one being selected, and if not, return
to the form.

--
-bts
-Friends don't let friends drive Vista
Mar 26 '08 #2

P: n/a
Beauregard T. Shagnasty wrote:
Yes. You still need to test in the action script.
Or in the cgi that processes the data, but I have to do that anyway.
>
Why can't you simply use two buttons, with neither hidden and neither
selected as "checked"? Such as:
Per the spec (html401 17.2.1 Control types),
"At all times, exactly one of the radio buttons in a set is checked. If
none of the <INPUTelements of a set of radio buttons specifies
`CHECKED', then the user agent must check the first radio button of the
set initially."

In the past I have had problems with different browsers complying to
varying degrees, and I don't want an inadvertent default to give me
permission the used didn't intend.
Mar 26 '08 #3

P: n/a
William Gill wrote:
Beauregard T. Shagnasty wrote:
>Yes. You still need to test in the action script.

Or in the cgi that processes the data, but I have to do that anyway.
>>
>Why can't you simply use two buttons, with neither hidden and neither
selected as "checked"? Such as:

Per the spec (html401 17.2.1 Control types),
"At all times, exactly one of the radio buttons in a set is checked. If
none of the <INPUTelements of a set of radio buttons specifies
`CHECKED', then the user agent must check the first radio button of the
set initially."

In the past I have had problems with different browsers complying to
varying degrees, and I don't want an inadvertent default to give me
permission the used didn't intend.
Drop list box? Ain't pretty but would satisfy your situation

<select name="permission">
<option value="">Please Select</option>
<option value="ayup">Yes</option>
<option value="nope">No</option>
</select>

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Mar 26 '08 #4

P: n/a
William Gill wrote:
Beauregard T. Shagnasty wrote:
>Yes. You still need to test in the action script.

Or in the cgi that processes the data, but I have to do that anyway.
Yes, that would be the script called by the form's action attribute.
>Why can't you simply use two buttons, with neither hidden and neither
selected as "checked"? Such as:

Per the spec (html401 17.2.1 Control types), "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."

In the past I have had problems with different browsers complying to
varying degrees, and I don't want an inadvertent default to give me
permission the used didn't intend.
I've an internal CMS that I use for doing input and data entry for a few
sites. In the pages to choose which record to edit, I have:

<input type="radio" name="radio1" value="Edit">Edit &nbsp;&nbsp;
<input type="radio" name="radio1" value="Add new">Add New&nbsp;&nbsp;
<input type="radio" name="radio1" value="Delete"Delete

...and in none of my numerous browsers is there a 'default' marked by
those browsers. This makes me think none of the UAs pay attention to the
rule you stated.
--
-bts
-Motorcycles defy gravity; cars just suck
Mar 26 '08 #5

P: n/a
Jonathan N. Little wrote:
Drop list box? Ain't pretty but would satisfy your situation

<select name="permission">
<option value="">Please Select</option>
<option value="ayup">Yes</option>
<option value="nope">No</option>
</select>
Same "trinary" approach with a "don't accept this one" default, but if I
"hide" the default, it seems to make more sense to the user who only see
two acceptable choices.
<label style="visibility:hidden">Select One <input name="Permission"
type="radio" value="unanswered" checked></label>
<label>Yes<input name="Permission" type="radio" value="yes"></label>
<label>No<input name="Permission" type="radio" value="no"></label>
Mar 26 '08 #6

P: n/a
Beauregard T. Shagnasty wrote:
I've an internal CMS that I use for doing input and data entry for a few
sites. In the pages to choose which record to edit, I have:

<input type="radio" name="radio1" value="Edit">Edit &nbsp;&nbsp;
<input type="radio" name="radio1" value="Add new">Add New&nbsp;&nbsp;
<input type="radio" name="radio1" value="Delete"Delete

..and in none of my numerous browsers is there a 'default' marked by
those browsers. This makes me think none of the UAs pay attention to the
rule you stated.
I used to do the same thing, not specifying which is initially checked,
until I ran into some problems, but it was a very long time ago. It may
be safer now.
Mar 26 '08 #7

P: n/a
William Gill wrote:
Beauregard T. Shagnasty wrote:
>I've an internal CMS that I use for doing input and data entry for a few
sites. In the pages to choose which record to edit, I have:

<input type="radio" name="radio1" value="Edit">Edit &nbsp;&nbsp;
<input type="radio" name="radio1" value="Add new">Add New&nbsp;&nbsp;
<input type="radio" name="radio1" value="Delete"Delete

..and in none of my numerous browsers is there a 'default' marked by
those browsers. This makes me think none of the UAs pay attention to the
rule you stated.

I used to do the same thing, not specifying which is initially checked,
until I ran into some problems, but it was a very long time ago. It may
be safer now.

But that is relying on an undefined behavior, usually a bad thing with
computers, I remember the old segmented memory wrap around hack that
programmers used that broke when the 286 came around... Will's got a
point, what if a browser that doesn't follow the current convention
becomes popular?

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Mar 26 '08 #8

P: n/a
Jonathan N. Little wrote:
William Gill wrote:
>Beauregard T. Shagnasty wrote:
>>I've an internal CMS that I use for doing input and data entry for a
few sites. In the pages to choose which record to edit, I have:

<input type="radio" name="radio1" value="Edit">Edit &nbsp;&nbsp;
<input type="radio" name="radio1" value="Add new">Add New&nbsp;&nbsp;
<input type="radio" name="radio1" value="Delete"Delete

..and in none of my numerous browsers is there a 'default' marked by
those browsers. This makes me think none of the UAs pay attention
to the rule you stated.

I used to do the same thing, not specifying which is initially
checked, until I ran into some problems, but it was a very long time
ago. It may be safer now.

But that is relying on an undefined behavior, usually a bad thing
with computers, I remember the old segmented memory wrap around hack
that programmers used that broke when the 286 came around... Will's
got a point, what if a browser that doesn't follow the current
convention becomes popular?
But should it matter? One of the radio buttons must be selected in any
case. Ok, I'll concede: if Firefox 7.0.23 shows one of them checked by
default, I'll alter my strategy. ;-)

--
-bts
-Friends don't let friends drive Vista
Mar 26 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.