I'm trying to find the sum of input values within multiple sections. I've put my code so far below.
The HTML:
<div class="section">
<input type="radio" name="q1" value="2"/>
<input type="radio" name="q2" value="0"/>
<input type="radio" name="q3" value="1"/>
<input type="radio" name="q4" value="3"/>
</div>
The jQuery:
$('.section').each(function(){
var totalPoints = 0;
$(this).find('input').each(function(){
totalPoints += $(this).val();
});
alert(totalPoints);
});
Please note this is a simplified version of the code I'm actually using. So I want this to alert 2 values (the sum of each section): 8 then 6. Instead I'm just getting a string of all the values. So the first section alerts 0143.
Any ideas how I get a cumulative sum instead of a string?