I am having a list of questions and for each question having 4 options. Now I want to know, which radio button is checked ?
Asked
Active
Viewed 19 times
1
-
1http://stackoverflow.com/questions/1423777/how-can-i-check-whether-a-radio-button-is-selected-with-javascript?rq=1 – Fidel90 Apr 14 '16 at 07:25
-
What you tried so far ? – Debug Diva Apr 14 '16 at 07:42
1 Answers
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