Store answer with javascript to temp array?
I have 10 questions with "YES" and "No" answers. I need user to answer all of them. If all answers marked as "Yes", "Next" button should be enabled. If at least one answer "No" disabled.
Could you please show me how it can be done with javascript or jquery library?
Here is an example of my HTML, lets assume I have 2 questions
<p>
Question?<br />
<input type="radio" name="Question1" value="Yes" />Yes
<input type="radio" name="Question1" value="No" />No
</p>
<p>
Question 2?开发者_JS百科<br />
<input type="radio" name="Question2" value="Yes" />Yes
<input type="radio" name="Question2" value="No" />No
<p>
<button id="next" type="button">Next</button>
$('input[type="radio"]').change(function(e){
var $yes = $('input[type="radio"][value="Yes"]');
if ($yes.filter(':checked').length === $yes.length) {
$('#next').attr('disabled', false);
} else {
$('#next').attr('disabled', true);
}
});
See example →
精彩评论