You are viewing limited content. For full access, please sign in.

Question

Question

Require a certain fields

asked on April 7, 2016

I have a test that has about 10 questions. The student has the option to only complete 5 questions. But I want it to be required they at least fill out 5 of the 10. Is there a way to do this with scripting.

0 0

Replies

replied on April 7, 2016 Show version history

Chynna,

The easiest way would be to create a field called "Questions Answered" or something similar. Make it a required field. You can use Javascript to make it read-only as well. You will want to ensure that the field has a range with a minimum-value of 5.

$('.answers input').prop('readonly', true);

Then use some Javascript to populate it based on whether the questions have been answered.

$('.question').on('change', 'input', function() {
  var answers = 0;
  $('.question input').each() {
    if ($(this).val()) {
      answers++;
    }
  }
  $('.answers input').val(answers).trigger('change');
});

Edit: Forgot to set language in code-block

1 0
replied on April 7, 2016 Show version history

John, Thanks this would definitely work. I am modifying a form I didn't create the structure and layout. They have sections than you have to complete the questions underneath the section.

Do you think I can make some type of formula so when they complete the whole section in a hidden field it  creates "1" point and once I have five pints I show the submit button? I don't want to make this go super complicated. Plus the questions types are a not "selection style" questions, they are "free response" questions.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.