Radio's

  • Thread starter Samuël van Laere
  • Start date
S

Samuël van Laere

Could someone explain me why the radio buttons are both selected when
clicking them??
Yeah I do something wrong here and have tried combinations but to no avail.
Thanks.

<p>Wil je een copie van je bericht ontvangen?<br>
<input class="input" type="radio" title="Ja ik wil een copie ontvangen"
name="Ja" id="Ja" value="1">
<label for="Ja">&nbsp;Ja stuur mij een copie</label>
<br>
<input class="input" type="radio" title="Nee ik wil geen copie ontvangen"
name="Nee" id="Nee" value="0">
<label for="Nee">&nbsp;Nee stuur mij geen copie</label>
<br>
</p>

Regards,
Samuël van Laere
the Netherlands
 
J

Jukka K. Korpela

Samuël van Laere said:
Could someone explain me why the radio buttons are both selected when
clicking them??

On which browser(s), for which specific URL?
<input class="input" type="radio" title="Ja ik wil een copie ontvangen"
name="Ja" id="Ja" value="1">
<label for="Ja">&nbsp;Ja stuur mij een copie</label>
<br>
<input class="input" type="radio" title="Nee ik wil geen copie
ontvangen" name="Nee" id="Nee" value="0">
<label for="Nee">&nbsp;Nee stuur mij geen copie</label>

In that code fragment, you have two radio buttons with different names.
They act independently of each other. A lone radio button is a really poor
lonesome button, since a) it is browser-dependent what happens if the user
does not click on it (a browser might treat it as initially checked) and
b) once clicked on, there's no normal way to change one's mind about it.

I guess what has happened is that you have clicked on one of them, then on
another, and this checks it without unchecking the other. But this is how
things _should_ be by HTML specifications. If you want to make them belong
together, the name="..." attributes must be the same. If you do that, you
should make one of the alternatives (probably the negative one) initially
checked.

On the other hand, a checkbox would be more natural for an on/off choice:

<input class="input" type="checkbox" name="copie" id="Ja" value="1">
<label for="Ja">&nbsp;Stuur mij een copie</label>
 
S

Samuël van Laere

Jukka K. Korpela said:
In that code fragment, you have two radio buttons with different names.
They act independently of each other. A lone radio button is a really poor
lonesome button, since a) it is browser-dependent what happens if the user
does not click on it (a browser might treat it as initially checked) and
b) once clicked on, there's no normal way to change one's mind about it.

I guess what has happened is that you have clicked on one of them, then on
another, and this checks it without unchecking the other. But this is how
things _should_ be by HTML specifications. If you want to make them belong
together, the name="..." attributes must be the same. If you do that, you
should make one of the alternatives (probably the negative one) initially
checked.

On the other hand, a checkbox would be more natural for an on/off choice:

<input class="input" type="checkbox" name="copie" id="Ja" value="1">
<label for="Ja">&nbsp;Stuur mij een copie</label>

Indeed I wanted the radio button to uncheck on clicking a different one,
it never occured to me that it is in the specification, let alone visit the
source :)
But i've used a checkbox now, its a whole lot better anyhow since I only
need to keep track of one value.
Thanks for clearing the air Yucca.


Regards,
Samuël van Laere
the Netherlands
 
T

Toby Inkster

Samuël van Laere said:
Could someone explain me why the radio buttons are both selected when
clicking them??

They have different values for the name attribute. Give them a common name.
 
J

Jeffrey Silverman

On the other hand, a checkbox would be more natural for an on/off choice:

<input class="input" type="checkbox" name="copie" id="Ja" value="1">
<label for="Ja">&nbsp;Stuur mij een copie</label>

Unless the items are mutually exclusive
 
N

Neal

Jeffrey:
Jukka:
Unless the items are mutually exclusive

True, but then it wouldn't be an on-off choice. If it's a multiple-choice,
radio buttons with the same name is best. If it's a yes/no, checkbox is
best.

In fact, radio buttons and select boxes serve a similar end - choosing one
option from a list. IMO radio buttons are more useful when there's a small
number of more detailed choices, and select box is best for a longer (but
not too long!) list of shorter choices.
 
J

Jeffrey Silverman

In fact, radio buttons and select boxes serve a similar end - choosing one
option from a list. IMO radio buttons are more useful when there's a small
number of more detailed choices, and select box is best for a longer (but
not too long!) list of shorter choices.

Huh? "select" box or "check" box?

select box (i.e. drop-down selector) and radio button are equivalent.

radio button and CHECK box are not.

Select box and check box are not.

check box and multi-select box are equivalent.

To make it even more clear (and I know you know this, Neal, but this is
for the benefit of others who might not and also to boost my alt.html
stats at the end of this week):

<input type="radio"> is equivalent to <select><option>...</option></select>

and

<input type="checkbox"> is quivalent to
<select MULTIPLE><option>...</option></select>

later...
 
N

Neal

Jeffrey Silverman:
Huh? "select" box or "check" box?

Select. Like I said.
check box and multi-select box are equivalent.

This is true. I didn't mention that. However, I rarely encounter multiple
select boxes. Nor do I use them, I'd think they'd be confusing to the user
more often than not.

Thanks for having me as a guest on the Jeffrey Silverman show. ;)
 
N

Neal

Jeffrey:
Right, but my point is just that "select" boxes were not mentioned in
this
post until you broguht them up.

That's also correct. I just added that as an aside, to illustrate to the
uninitiated how the various form controls match up to one another. Seemed
a shame to discuss radio and check without also mentioning select. It
might feel left out, and cry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

I dont get this. Please help me!! 2
<div> help 1
How can I arrange a series of radio buttons? 2
"input-group-text" help 7
Positioning CSS components 1
Check forms With JavaScript 1
Help please 8
Song requests 4

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top