Welcome to the LimeSurvey Community Forum

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

Restrict User on filling wrong response

  • saifshaikh
  • saifshaikh's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 3 weeks ago #159517 by saifshaikh
Restrict User on filling wrong response was created 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.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 3 weeks ago - 7 years 3 weeks ago #159531 by tpartner
Replied by tpartner on topic Restrict User on filling wrong response
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 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 7 years 3 weeks ago by tpartner.
The following user(s) said Thank You: saifshaikh
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 3 weeks ago #159532 by Joffm
Replied by Joffm on topic Restrict User on filling wrong response
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.
  • saifshaikh
  • saifshaikh's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 3 weeks ago #159576 by saifshaikh
Replied by saifshaikh on topic Restrict User on filling wrong response
Thank you! Tony
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose