2

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?<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>
3
  • I'm thinking to add answers to array and then compare it. but the problem is I don't have so much experience on client side Commented May 10, 2011 at 18:40
  • too much left unsaid... your yes and no, are they drop down menus, are they radio buttons? What is the id/name/value/class of the items? It would be very helpful if you provided the actual html you are working with. Commented May 10, 2011 at 18:42
  • I updated my question with HTML example Commented May 10, 2011 at 18:52

1 Answer 1

2
$('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 →

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.