Welcome to the LimeSurvey Community Forum

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

filtering for drop down menus?

More
10 years 1 week ago #106010 by dale
filtering for drop down menus? was created by dale
I am trying to get the selections for a drop down menu to populate using only choices that are sourced from a previous question that is a Multiple Short Text question.

The catch is that the previous question has 7 sub questions, but respondents don't have to answer all of the sub questions, (in my case the subquestions are just asking for a list of people on a team, and it could be anywhere from 2-7 people)

I can get the drop down to populate with all 7 answers, but I don't want it to show blank answers as a possible option if the team has fewer than 7 players. If only 4 people are on their team, I want the drop down menu in the latter question to only display those 4 names to select from.

Alternately I tried using an array with radio buttons and having the players names as the cumn headings, but I have learned that Limesurvey currently does not allow filtering array columns.

Any work arounds for this predicament?

example:
Q1: List your team members
SQ1:
SQ2:
SQ3:
SQ4:
SQ5:
SQ6:
SQ7:


Q2: Who do you think should win the MVP?
(And here is where I need to somehow, some way, list all the people listed in Q1, and no blanks, leaving respondents the option to pick only one.

I appreciate any help!
Attachments:
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 1 week ago #106011 by tpartner
Replied by tpartner on topic filtering for drop down menus?
Sorry, I don't see Q2 anywhere in that survey and it's far too long with too many mandatory questions for me to wade through.


.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: dale
The topic has been locked.
More
10 years 1 week ago #106012 by dale
Replied by dale on topic filtering for drop down menus?
Oh! Sorry! I just called it Q2 for the sake of simplicity in the example. In the survey the first question where respondent list team mates is QID 2 and the question that I'm trying to make a drop down for is QID 110 if that helps.

All the other mandatory questions in between are irrelevant to QID 110, and do not affect QID 2

Thank you for checking into it!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 1 week ago #106013 by tpartner
Replied by tpartner on topic filtering for drop down menus?
QIDs don't help as they are changed during the import process.

Can you attach a survey with only the pertinent questions?


.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
10 years 1 week ago #106014 by dale
Replied by dale on topic filtering for drop down menus?
This should have the bare minimum for the question at hand. I have included two questions using both approaches I've tried: the drop down menu and the array.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 1 week ago - 10 years 1 week ago #106037 by tpartner
Replied by tpartner on topic filtering for drop down menus?
Okay, lets point out for other readers that you are using INSERTANS or Expression Manager to pipe the answer values from a multiple-short-text into the options of a drop-down and into the headers of an array.

Given that the drop-down and array questions are on following pages, we can use JavaScript to "filter" all empty drop-down options and array columns. Here are solutions for both question types.

Set up your survey to use JavaScript .

Add this script to the source of the drop-down question:
Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function(){
 
    // Identify the question
    var q1ID = '{QID}';
 
    // Remove all options that have no text
    $('#question'+q1ID+' option').filter(function() {
      return $(this).text() == '';
    }).remove(); 
  });
</script>

Add this script to the source of the array question:
Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function() { 
 
    // Identify the question
    var q1ID = '{QID}';
    var q1ID = 17571;
    var q1 = $('#question'+q1ID+'');
 
    // Add some column-specific classes
    $('table.subquestions-list tr', q1).each(function(i){
      $('> *', this).each(function(i){
        $(this).attr('data-column', 'col-'+i);
      });
    });
 
    // Hide all columns with empty headers
    $('table.subquestions-list thead th', q1).each(function(i){
      if($(this).text() == '') {
        $('table.subquestions-list [data-column="'+$(this).attr('data-column')+'"]', q1).hide();
      }
    });
 
  });
</script>

Here is your test survey back with these scripts inserted:

File Attachment:

File Name: limesurvey...9524.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: 10 years 1 week ago by tpartner.
The following user(s) said Thank You: dale
The topic has been locked.
More
10 years 1 week ago #106139 by dale
Replied by dale on topic filtering for drop down menus?
Thank you so much for spelling it all out like this for me! I'll be adding it in today
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose