Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to identify which radio button is accepted?

How can I identify which radio button is accepted?

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.

like image 233
sark9012 Avatar asked Jul 04 '10 20:07

sark9012


2 Answers

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 />
like image 123
superUntitled Avatar answered Oct 24 '22 20:10

superUntitled


you should give them the same name

like image 24
Sergey Eremin Avatar answered Oct 24 '22 19:10

Sergey Eremin