tags:

views:

48

answers:

2

Hey guys, Just a simple one for most of you i imagine! How do I prevent a user being able to select multiple options when I use radio buttons?

<input type='radio' name='one'>option1<br />
<input type='radio' name='two'>option2<br />
<input type='radio' name='three'>option3<br />
<input type='radio' name='four'>option4<br />
<input type='radio' name='five'>option5<br />

Thats the code I use, thanks for reading.

I have edited for the following: How can I identify which radio button is accepted? Is there a clever trick for this?

+3  A: 

you should give them the same name

kgb
And different values.
casablanca
+8  A: 

You need to use the "name" attribute to tie them all together, use the value attribute to give them different values.

<input type="radio" name="number" value="one" /> One<br />
<input type="radio" name="number" value="two" /> Two<br />
<input type="radio" name="number" value="three" /> Three<br />

Think of name as last name... For example, if you had Bart, Lisa, Homer, Marge and Maggie, the name would be their last name: Simpson, the value would be the said names:

<input type="radio" name="Simpson" value="Bart" /> Bart<br />
<input type="radio" name="Simpson" value="Lisa" /> Lisa<br />
<input type="radio" name="Simpson" value="Marge" /> Marge<br />
<input type="radio" name="Simpson" value="Homer" /> Homer<br />
<input type="radio" name="Simpson" value="Maggie" /> Maggie<br />
superUntitled
Great answer, very useful.I will give this the green tick as soon as it allows me.Thanks bud.
Luke
So what if i need to know which button was selected?Is that possible?
Luke
The value will be the one which was selected.
casablanca