Home » Django » how to set that only one radio button can be checked

how to set that only one radio button can be checked

Posted by: admin November 30, 2017 Leave a comment

Questions:
{% for each in AnswerQuery %}
<form action={{address}}>
<span>{{each.answer}}</span><input type='radio'>
<span>Votes:{{each.answercount}}</span>
<br>
</form>
{% endfor %}

this is a part my django template, what it supposed to do is to print out several radio button corresponding to the answers assigned to the buttons. But I dont know why that I can check multiple radio buttons, which messed me up. It is supposed to only let me check on one radio button and I had that somehow but I lost it. Any help? Thank you

Answers:

Simply give them the same name:

<input type="radio" name="radAnswer" />

Questions:
Answers:

They need to all have the same name.

Questions:
Answers:

All radio buttons have to have the same name:

<input type='radio' name='foo'>

Only 1 radio button of each group of buttons with the same name can be checked.

Questions:
Answers:

Give them the same name, and it will work. By definition Radio buttons will only have one choice, while check boxes can have many.

<input type="radio" name="Radio1" />

Questions:
Answers:

Just give them the same name throughout the form you are using.

<form><input type="radio" name="selection">
      <input type="radio" name="selection">
      ..
      ..
</form>