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!
To check only those specific groups:
$(':radio[name="rdQueen"]:checked, :radio[name="rdFruit"]:checked').length; You can do:
var numberOfCheckedRadio = $('input:radio:checked').length //this gives you the total of checked radio buttons on the page Use checked-selector [docs] to get those and length [docs] to see how many were there.
alert( $('input:radio:checked').length );