Restrict User on filling wrong response

More
1 month 1 week ago #159517 by saifshaikh
saifshaikh created the topic: Restrict User on filling wrong response
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
Attachments:

Please Log in to join the conversation.

More
1 month 1 week ago - 1 month 1 week ago #159531 by tpartner
tpartner replied the 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:
    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:
<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 && 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:
    (!is_empty(Q1) AND !is_empty(Q2)) AND intval(Q1) < intval(Q2)
  • Question Validation Equation:
    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:
    <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.
Attachments:
Last Edit: 1 month 1 week ago by tpartner.
The following user(s) said Thank You: saifshaikh

Please Log in to join the conversation.

More
1 month 1 week ago #159532 by Joffm
Joffm replied the 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.
https://www.limesurvey.org/forum/can-i-do-this-with-limesurvey/112431-hide-a-listradio-option-based-on-the-answer-to-previous-listradio-question
The following user(s) said Thank You: saifshaikh

Please Log in to join the conversation.

More
1 month 1 week ago #159576 by saifshaikh
saifshaikh replied the topic: Restrict User on filling wrong response
Thank you! Tony

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!