Welcome, Guest
Username: Password: Remember me

TOPIC: check that answers from two identical drop down list are different

check that answers from two identical drop down list are different 4 months 2 weeks ago #107176

  • pmonstad
  • pmonstad's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 10
  • Karma: 1
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?
The administrator has disabled public write access.

check that answers from two identical drop down list are different 4 months 2 weeks ago #107182

  • holch
  • holch's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 2608
  • Thank you received: 302
  • Karma: 111
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.
Have a look at the manual! It is a really valuable source for information. Here some helpful links:
Manual (EN) | Question Types | Question Attributes | Workarounds

If you found this answer helpful and it saved you some time please consider a donation to the project to keep Limesurvey going!
The administrator has disabled public write access.

check that answers from two identical drop down list are different 4 months 2 weeks ago #107184

  • pmonstad
  • pmonstad's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 10
  • Karma: 1
Yes, they are at the same page.
The administrator has disabled public write access.

check that answers from two identical drop down list are different 4 months 2 weeks ago #107185

  • holch
  • holch's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 2608
  • Thank you received: 302
  • Karma: 111
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.
Have a look at the manual! It is a really valuable source for information. Here some helpful links:
Manual (EN) | Question Types | Question Attributes | Workarounds

If you found this answer helpful and it saved you some time please consider a donation to the project to keep Limesurvey going!
The administrator has disabled public write access.

check that answers from two identical drop down list are different 4 months 2 weeks ago #107204

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4118
  • Thank you received: 760
  • Karma: 346
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.124 seconds
Donation Image