1

I am having a list of questions and for each question having 4 options. Now I want to know, which radio button is checked ?

1 Answers1

0

If the radio buttons have ids you could use:

if (document.getElementById('radioId').checked){
    //do something
}

If you have loads of them you could use:

var radioButtons = document.getElementsByName('radioButtonName');

To get all the radio buttons that have that name field and then loop through them all with a for loop with an if statement to see if they are checked inside.

for(i=0;i<radioButtons.length;i++){
    if(radiobutton[i].checked){
        //do something
    }
}
Ben Rhys-Lewis
  • 3,118
  • 8
  • 34
  • 45