suppose I have groups of radio buttons like so:
<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 />
... sometime later in 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 atleast one of them from both group has been selected.. so I need to count the radiobuttons that have been checked, in this case it'll be 2.
Only, I am not sure how to do that. help please!
You could do:
var numberOfCheckedRadio = $('input:radio:checked').length
//this gives you the total of checked radio buttons on the page
To check for only those specific groups:
$(':radio[name="rdQueen"]:checked, :radio[name="rdFruit"]:checked').length;
Example: http://jsfiddle.net/AlienWebguy/HzfKq/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With