views:

938

answers:

1

hi ,,

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

+9  A: 

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

Paolo Bergantino
what if the radio buttons have different name like : physics will have two radio buttons with same name so that they can choose betn A and As physics like wise two radio buttons for biology, and like wise for other 11 subjects , how can i get the values of the checked radio buttons only?
jarus
The first example would get the values of all the checked ones.
Paolo Bergantino
Thanks ! Its helped me.
santosh