Welcome, Guest
Username: Password: Remember me

TOPIC: filtering for drop down menus?

filtering for drop down menus? 5 months 3 weeks ago #106010

  • dale
  • dale's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
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 administrator has disabled public write access.

filtering for drop down menus? 5 months 3 weeks ago #106011

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4139
  • Thank you received: 767
  • Karma: 348
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: dale

filtering for drop down menus? 5 months 3 weeks ago #106012

  • dale
  • dale's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
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 administrator has disabled public write access.

filtering for drop down menus? 5 months 3 weeks ago #106013

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4139
  • Thank you received: 767
  • Karma: 348
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

filtering for drop down menus? 5 months 3 weeks ago #106014

  • dale
  • dale's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
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.
Attachments:
The administrator has disabled public write access.

filtering for drop down menus? 5 months 3 weeks ago #106037

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4139
  • Thank you received: 767
  • Karma: 348
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:
<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:
<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_survey_999524.lss
File Size: 25 KB
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.
Last Edit: 5 months 3 weeks ago by tpartner.
The administrator has disabled public write access.
The following user(s) said Thank You: dale

filtering for drop down menus? 5 months 3 weeks ago #106139

  • dale
  • dale's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
Thank you so much for spelling it all out like this for me! I'll be adding it in today
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.126 seconds
Donation Image