I've looked through a few StackOverflow pages and nothing has helped. I've made a quiz using HTML radio buttons. The questions and answers are not generated dynamically. Each question has possible answers and the correct answer has a value of 'right'. I want to check all radios that have been selected by the user upon submit and if their value is == to right then I want to add a point (r+=1).
My HTML looks like this (x9).
<div class='col-sm-12 col-md-6 col-lg-4 text-center'>
<p class='question'>Which version of IE supports SSE?</p>
<div class='form-check'>
<input class='form-check-input' type='radio' name='htmlq9a'>
<label class='form-check-label' for='htmlq9a'>Internet explorer 10+</label>
</div>
<div class='form-check'>
<input class='form-check-input' type='radio' name='htmlq9a'>
<label class='form-check-label' for='htmlq9a'>Internet explorer 9+</label>
</div>
<div class='form-check'>
<input class='form-check-input' type='radio' name='htmlq9a'>
<label class='form-check-label' for='htmlq9a'>Internet explorer 8+</label>
</div>
<div class='form-check'>
<input class='form-check-input' type='radio' name='htmlq9a' value='right'>
<label class='form-check-label' for='htmlq9a'>Internet explorer does not support SSE.</label>
</div>
</div>
And my javascript looks like this.
var r = 0;
var tr = 9;
var m = 100;
var fs;
$('#sub').click(function(e){
e.preventDefault();
$('input:checked').each(
if( $(this).val() == 'right' ){
r+=1;
}
}
});
var fs = (r/tr) * m;
$('#as').html(fs);
label'sforattribute points to anid, not a class.