How to determine which switch is accepted?

How can I determine which switch is accepted?

How can I prevent a user from selecting multiple options when using 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 />

Here is the code I'm using, thanks for reading.

+5
source share
4 answers

You need to use the name attribute to bind 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 the name as a surname ... For example, if you had Bart, Lisa, Homer, Marge and Maggie, the name would be their last name: Simpson, meaning would be the following 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 />
+26
source

you must give them the same name

+4
source

/.

0
source

I know! Do the following:

<label><input type="radio" name="a">1</label>
<label><input type="radio" name="a">2</label>
<label><input type="radio" name="a">3</label>

Give all the same value for the name attribute. You add a name for the switches

0
source

All Articles