Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Restrict User on filling wrong response

More
7 years 10 months ago #159517 by saifshaikh
Hi,

Can we restrict user from selecting wrong response.

eg.

Stores Visited (Q1) should always be greater than Stores Purchased (Q2)

Q1 - Store Visited
Answer Option (List Radio)
One
Two
Three
Four
Five
Six
Seven
Eight
None

Q2 - Stores Purchased
Answer Option (List Radio)
No Purchase
One
Two
Three
Four
Five
Six
Seven
Eight
None

I have attached a sample survey.

Thanks
Saif
The topic has been locked.
More
7 years 10 months ago - 7 years 10 months ago #159531 by tpartner
There is no Question Validation Equation for list-radio questions so you need to use one or both of the following workarounds (similar to this post ):
  1. Insert JavaScript to disable the Next/Submit button if Q1 < Q2
  2. Insert a short-text question after the radio questions with a Question Validation Equation something like:
    Code:
    intval(Q1) >= intval(Q2)

I have added both workarounds to your sample survey (attached below) as follows...

1) Added the following script to Q1 to disable the Next/Submit button if Q1 < Q2:
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:complete',function() {
    // Listener on radios
    var questions = $('.list-radio:lt(2)');
    var q1 = $('.list-radio:eq(0)');
    var q2 = $('.list-radio:eq(1)');
    $('input[type="radio"]', questions).on('change', function(e) {
      var q1Answer = Number($('input[type="radio"]:checked', q1).val());
      var q2Answer = Number($('input[type="radio"]:checked', q2).val());
      if($('input[type="radio"]:checked', questions).length == 2 &amp;&amp; q1Answer < q2Answer) {
        $('#movenextbtn, #movesubmitbtn').prop('disabled', true);
      }
      else {
        $('#movenextbtn, #movesubmitbtn').prop('disabled', false);
      }
    });
  });
</script>

2) Inserted a short-text question after the radio questions with the following features:
  • Relevance:
    Code:
    (!is_empty(Q1) AND !is_empty(Q2)) AND intval(Q1) < intval(Q2)
  • Question Validation Equation:
    Code:
    intval(Q1) >= intval(Q2)
  • Question Validation Tip: Q2 must be less than or equal to Q1.
  • Inserted script to hide the answer element and style the text elements:
    Code:
    <script type="text/javascript" charset="utf-8">
      $(document).on('ready pjax:complete',function() {
        // Clean up the question appearance
        $('#question{QID} .answer-container').remove();
        $('#question{QID} .question-title-container').css('padding', '0');
        $('#question{QID} .questionvalidcontainer').css('padding', '1em');
      });
    </script>



Survey attached:

File Attachment:

File Name: limesurvey...7998.lss
File Size:25.44 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 7 years 10 months ago by tpartner.
The following user(s) said Thank You: saifshaikh
The topic has been locked.
More
7 years 10 months ago #159532 by Joffm
And you could try this:
equation fills a hidden multiple with the remaining answer options.
This multiple is matrix filter of next question.
www.limesurvey.org/forum/can-i-do-this-w...s-listradio-question

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: saifshaikh
The topic has been locked.
More
7 years 10 months ago #159576 by saifshaikh
Thank you! Tony
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose