Reputation: 1873
can we get the values of the radio buttons , only those which has been checked , cause i have to implement a form in which there are many radio buttons , so how can i get all the values which has been checked what i have to do is
i have 13 subjects like : physics , math , biology ..... and the students can choose any number of subjects , and each subject will have two radio buttons one is A and the another is As ,
so how can i get the values of the radio buttons which has been checked? using jquery
Upvotes: 1
Views: 7559
Reputation: 488374
This would loop through all the radio elements in the document that have been checked:
$('input:radio:checked').each(function() {
var value = $(this).val();
// do something with radio or value
});
If you wanted to get the checked value of a particular radio group, you would do:
var value = $('input:radio[name=myradios]:checked').val();
So if your HTML was like this:
<input type='radio' name='myradios' value='1'>
<input type='radio' name='myradios' value='2' checked='checked'>
<input type='radio' name='myradios' value='3'>
value
would be 2
Upvotes: 9