Welcome to the LimeSurvey Community Forum

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

check that answers from two identical drop down list are different

  • pmonstad
  • pmonstad's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 11 months ago #107176 by pmonstad
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 topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 11 months ago #107182 by holch
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 answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • pmonstad
  • pmonstad's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 11 months ago #107184 by pmonstad
Yes, they are at the same page.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 11 months ago #107185 by holch
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 answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 11 months ago #107204 by tpartner
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.

Code:
<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() != '' &amp;&amp; $('.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.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose