Counting Checked Radio Buttons with jQuery
jquery
Solution
Try the following:
$(document).ready(function() {
$('input:radio').change(function(){
var yes = $('.yes:checked').length
var no = $('.no:checked').length
$('.yes_results').text(yes)
$('.no_results').text(no)
})
});
DEMO
Problem
I have pages with varying numbers of radio buttons. These buttons have two different classes, `yes`, and `no`. As the user goes down the page, I need to figure out how many of each class they have selected, and display it in a `<p>` at the bottom of the page. I'm having problems preventing 1 getting added to the variable when a user clicks on a radio button more than once. Here's a JS fiddle with my code: http://jsfiddle.net/AnWU3/3/ It's not working at all for some reason, and I don't see why.