Reputation: 325
I am unable to select one radio button at a time. Multiple buttons are getting selected. I am newbie to html. This is my code. Please help.
<form name="ans_a" onsubmit="return answer_a()">
<table align="center" border="1">
<br>
<br>
<tr>
<td width="500px"> ABC
<br>
<input type="radio" name="A" value="a" id="radio1"> A   Option A <br>
<input type="radio" name="B" value="b" id="radio2"> B   Option B <br>
<input type="radio" name="C" value="c" id="radio3"> C   Option C <br>
<input type="radio" name="D" value="d" id="radio4"> D   Option D <br>
<br>
                 
<input type="button" name="ans1" value="Next" onclick="answer_a()">
</td>
</tr>
</table>
</form>
Upvotes: 7
Views: 24961
Reputation: 27382
The name attribute must be the same to select only one radio button
at a time. The id could be different depending on if you want to capture that somewhere which one of the radio buttons is selected.
<input type="radio" name="A" value="a" id="radio1"> A   Option A <br>
<input type="radio" name="A" value="b" id="radio2"> B   Option B <br>
<input type="radio" name="A" value="c" id="radio3"> C   Option C <br>
<input type="radio" name="A" value="d" id="radio4"> D   Option D <br>
Upvotes: 15
Reputation: 109
try same name for all the radio buttons i used like this in my project
<div class="col-md-2"> <label><input type="radio" class="classone" name="A">Daily</label> </div>
<div class="col-md-2"> <label><input type="radio" class="classone" name="A">Weekly</label> </div>
<div class="col-md-2"> <label><input type="radio" class="classone" name="A">Monthly</label> </div>
<div class="col-md-2"> <label><input type="radio" class="classone" name="A">Yearly</label> </div>
Upvotes: 0
Reputation: 4465
To select only one radio button, you have to put them under one group, i.e make the name attribute same for all of them.
<input type="radio" name="options" value="a" id="radio1"> A   Option A <br>
<input type="radio" name="options" value="b" id="radio2"> B   Option B <br>
<input type="radio" name="options" value="c" id="radio3"> C   Option C <br>
<input type="radio" name="options" value="d" id="radio4"> D   Option D <br>
Upvotes: 3