check that answers from two identical drop down list are different

More
3 years 2 months ago #107176 by pmonstad
pmonstad created the topic: check that answers from two identical drop down list are different
I have two identical drop down lists. The respondent is supposed to make a first choice from the first list and a second choice from the second list. Making two identical choices make no sense but will certainly happen when several hundred kids are about to answer.

How can I make a check of the two answers? Only continue if the two answers are different, and show an error if they equals redirecting the respondent to make another choice in on of the lists?

Please Log in to join the conversation.

More
3 years 2 months ago #107182 by holch
holch replied the topic: check that answers from two identical drop down list are different
I assume that the lists are both on the same page?

If they are on different pages, you might be able to use the array_filter (not sure if it works with the dropdowns though.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in to join the conversation.

More
3 years 2 months ago #107184 by pmonstad
pmonstad replied the topic: check that answers from two identical drop down list are different
Yes, they are at the same page.

Please Log in to join the conversation.

More
3 years 2 months ago #107185 by holch
holch replied the topic: check that answers from two identical drop down list are different
I have just checked and the dropdown question doesn't have the option of array filter anyway, so this is not an option. There might be a solution with Javascript, but I have no idea.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in to join the conversation.

More
3 years 2 months ago #107204 by tpartner
tpartner replied the topic: check that answers from two identical drop down list are different
Assuming there are only two dropdowns on the page or the dropdowns are sequential, you can set up your survey to use JavaScript and add this script to the question source of the first dropdown.

This script will interrupt the submit process and compare the dropdown values.

<script type="text/javascript" charset="utf-8">	
 
	$(document).ready(function() {
 
		// Identify the questions
		var q1 = $('#question'+{QID}+'');
		var q2 = $(q1).nextAll('.list-dropdown:eq(0)');
		var alertText = 'The two dropdowns cannot have the same answer.';
 
		// On submit, compare the 2 dropdown values
		$('#movenextbtn, #movesubmitbtn').click(function(){
			if($('.answer-item select', q1).val() != '' && $('.answer-item select', q1).val() == $('.answer-item select', q2).val()) {
				alert(alertText);
				return false;
			}
		});
	});
</script>


.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now