1

I want to build a questionnaire in HTML. Every question in the list can be answered by selecting one of four radiobuttons.

The problem I am facing is that I can only select one choice on the whole page, while I want to be able to select one choice per question.

When I have a list of questions and I have picked an alternative for question 1, I turn to question 2.

When I select an alternative for question 2, the chosen radiobutton for question 1 is deselected.

The radiobuttons for different questions have different names, the radiobuttons for 1 question have the same name. I included every question in a fieldset, but that does not work.

Does anyone know how to accomplish this? Any help will be greatly appreciated.

2
  • 3
    Share some example code, please.
    – omnichad
    Commented Mar 31, 2016 at 15:09
  • 1
    Please note that this site is not a code writing service. If you edit your question to describe what you have tried so far and where you are stuck, then we can try to help with specific problems. You should also read How to Ask. Commented Mar 31, 2016 at 15:35

1 Answer 1

1

You have to group your radio buttons by name:

 <input type="radio" name="group1" value="one">One<br>
 <input type="radio" name="group1" value="two">Two<br>
 <input type="radio" name="group1" value="three">Three<br>
 <input type="radio" name="group1" value="four">Four<br><br>

 <input type="radio" name="group2" value="a">a<br>
 <input type="radio" name="group2" value="b">b<br>
 <input type="radio" name="group2" value="c">c<br>
 <input type="radio" name="group2" value="d">d<br>

https://jsfiddle.net/ajjbfj0v/2/

2
  • Note that the OP states: "The radiobuttons for different questions have different names, the radiobuttons for 1 question have the same name". Commented Mar 31, 2016 at 16:05
  • Thanks Oscar, but as Jiri Tousek mentioned, I already had the names for different questions were already different, so this does not help the problem.
    – Paulus62
    Commented Apr 1, 2016 at 19:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.