Scaramouche

Number of selected radio buttons in jquery

Suppose I have switch groups:

<label><input type="radio" value="1" name="rdQueen" /> Scaramouche</label> <br /> <label><input type="radio" value="1" name="rdQueen" /> Will you do the</label> <br /> <label><input type="radio" value="1" name="rdQueen" /> Fandango</label> <br /> 

... after a while on the page ...

 <label><input type="radio" value="1" name="rdFruit" /> Mango</label> <br /> <label><input type="radio" value="1" name="rdFruit" /> Kiwi</label> <br /> <label><input type="radio" value="1" name="rdFruit" /> Potato</label> <br /> 

All I want to do is make sure that at least one of them is selected from both groups. Therefore, I need to count the verified radio ads, in which case it will be 2.

Only, I do not know how to do this. help me please!

+7
source share
3 answers

To check only those specific groups:

 $(':radio[name="rdQueen"]:checked, :radio[name="rdFruit"]:checked').length; 

Example: http://jsfiddle.net/AlienWebguy/HzfKq/

+11
source

You can do:

  var numberOfCheckedRadio = $('input:radio:checked').length //this gives you the total of checked radio buttons on the page 
+7
source

Use checked-selector [docs] to get those and length [docs] to see how many were there.

 alert( $('input:radio:checked').length ); 
+4
source

All Articles