Welcome, Guest
Username: Password: Remember me

TOPIC: Filter/disable answers depending on other questions answer

Re: Filter/disable answers depending on other questions answer 3 years 1 month ago #67657

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4364
  • Thank you received: 827
  • Karma: 381
The attachment didn't attach.
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.

Re: Filter/disable answers depending on other questions answer 3 years 1 month ago #67658

  • cegreja
  • cegreja's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 25
  • Karma: 0
It was too big. It's ok now.
The administrator has disabled public write access.

Re: Filter/disable answers depending on other questions answer 3 years 1 month ago #67659

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4364
  • Thank you received: 827
  • Karma: 381
Okay, I take back what I said about the script being simple.

Q1 is NOT a single multiple choice. It is, in fact, 3 dropdowns and 6 short-text questions layed out to look like a single array.

I'm afraid this is too complex for this forum.
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.

Re: Filter/disable answers depending on other questions answer 3 years 1 month ago #67660

  • cegreja
  • cegreja's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 25
  • Karma: 0
I'll have to rethink it then :unsure: How about the one that seems more simple?

Q4 = Q1+Q2+Q3 answers (the 3 choices from the 3 first questions in the group)

It's my last question, I promise. Thanks
The administrator has disabled public write access.

Re: Filter/disable answers depending on other questions answer 3 years 1 month ago #67680

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4364
  • Thank you received: 827
  • Karma: 381
I'm afraid I don't understand. Q1 (in group 1) is actually 9 questions, 6 of which are short-texts. There is no way to use short-text entries as a filter.
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.

Re: Filter/disable answers depending on other questions answer 3 years 1 month ago #67689

  • cegreja
  • cegreja's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 25
  • Karma: 0
Sorry, when I say Q1 I'm referring to the first question of the second group. I realise in the first group the questions don't allow for the solution I'm seeking. In the last example I gave you, I was referring to the creation of an array that had as secondary questions (the options in the rows of the array... I'm not sure how to name them in english) the 3 answers previously selected in each of the 3 ranking questions that precede the new questions. That is why I was reffering to them as Q1, Q2, Q3 and the new question would be Q4 (it already exists in the sample, but is showing all the 50 possible answers, not the filtered 9 ones I wanted to).

I'm sorry for taking so much of your time. This being too complex, is there any way to create an array filter from more than just one multiple options question? That way I could change the ranking questions into multiops and filter the answers checked in each one, that would appear in the new array as secondary questions.
The administrator has disabled public write access.

Re: Filter/disable answers depending on other questions answer 3 years 1 month ago #67700

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4364
  • Thank you received: 827
  • Karma: 381
1) Set up your survey to use JavaScript.

2) Add the following script to the source of the one of the questions in group 2. Replace "11", "22", "33" and "44" (line 5) with the Q1, Q2, Q3 and Q4 question question IDs respectively.

On page load, the script fires a filtering function that looks for all ranked items in Q1, Q2 and Q3 and displays only the corresponding rows in Q4 (the array). A listener on the ranking question fires the filtering script whenever a change is made.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		rankFilter3 (11, 22, 33, 44);
 
		// Filter an array by the results of 3 previous ranking questions
		function rankFilter3 (q1ID, q2ID, q3ID, q4ID) {
 
			// Add some classes to elements for manipulation
			$('#question'+q1ID+', #question'+ q2ID+', #question'+ q3ID+'').addClass('filterQ');
			$('#question'+q4ID+' tbody[id^="javatbd"]').each(function(i){
				idArr = $(this).attr('id').split('X'+q4ID);
				$(this).addClass('id-'+idArr[1]);
			});
 
			// Fire the filter function on page load
			runFilter();
 
			// Listeners on the ranking questions
			$('.filterQ td.label, .filterQ td.output img').click(function(){
				// Fire the filter function 
				runFilter();
			});
 
			// A function to filter an array depending on the results of previous ranking questions
			function runFilter() {
				// Hide all rows of the array
				$('#question'+q4ID+' tbody[id^="javatbd"]').hide()
				// Find all ranked items and show corresponding rows in the array
				$('.filterQ input[id^="fvalue"]').each(function(i){
					$('#question'+q4ID+' tbody.id-'+$(this).val()+'').show();
				});
				// Uncheck all radion in the array
				$('#question'+q4ID+' tbody[id^="javatbd"]:hidden input.radio').attr('checked', 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.
Last Edit: 3 years 1 month ago by tpartner.
The administrator has disabled public write access.
The following user(s) said Thank You: cegreja

Re: Filter/disable answers depending on other questions answer 3 years 1 month ago #67701

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4364
  • Thank you received: 827
  • Karma: 381
subquestions in Q5 = "marcav1" + "marcav2" + "marcav3" + checked answers in Q1 + Q2 + Q3
What are "marcav1", "marcav2" and "marcav3"?
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.

Re: Filter/disable answers depending on other questions answer 3 years 1 month ago #67726

  • cegreja
  • cegreja's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 25
  • Karma: 0
Thank you so much! That worked perfectly.
I'm doing this as a voluntary job but if the project goes ahead and I get paid, the first thing i'll do is make you guys a generous donation. Great work you're doing here helping everyone who don't know a thing about programming.

The "marcav1" etc were the labels of the questions in the first group I wanted to retrieve as rows for the new questions. But since they are short texts, nevermind.

Thanks again!
The administrator has disabled public write access.

Re: Filter/disable answers depending on other questions answer 3 years 1 month ago #67727

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4364
  • Thank you received: 827
  • Karma: 381
Okay, for this requirement:
subquestions in Q5 = "marcav1" + "marcav2" + "marcav3" + checked answers in Q1 + Q2 + Q3

You can use {INERTANS} to pipe the values of the short-texts into the answer labels for Q5 (you will need to modify the SGQA values for your question IDs).
Capture5.PNG


Then add this script to one of the questions in group2 (replace "55" with the Q5 ID). It does the same filtering as my previous script but always leaves the first 3 rows of Q5 visible.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		rankFilter4 (11, 22, 33, 55);
 
		// Filter an array by the results of 3 previous ranking questions AND always show the first 3 rows
		function rankFilter4 (q1ID, q2ID, q3ID, q5ID) {
 
			// Add some classes to elements for manipulation
			$('#question'+q1ID+', #question'+ q2ID+', #question'+ q3ID+'').addClass('filterQ');
			$('#question'+q5ID+' tbody[id^="javatbd"]').each(function(i){
				idArr = $(this).attr('id').split('X'+q5ID);
				$(this).addClass('id-'+idArr[1]);
			});
 
			// Fire the filter function on page load
			runFilter();
 
			// Listeners on the ranking questions
			$('.filterQ td.label, .filterQ td.output img').click(function(){
				// Fire the filter function 
				runFilter();
			});
 
			// A function to filter an array depending on the results of previous ranking questions
			function runFilter() {
				// Hide all rows of the array
				$('#question'+q5ID+' tbody[id^="javatbd"]').hide();
				$('#question'+q5ID+' tbody[id^="javatbd"]:eq(0)').show()
				$('#question'+q5ID+' tbody[id^="javatbd"]:eq(1)').show()
				$('#question'+q5ID+' tbody[id^="javatbd"]:eq(2)').show()
				// Find all ranked items and show corresponding rows in the array
				$('.filterQ input[id^="fvalue"]').each(function(i){
					$('#question'+q5ID+' tbody.id-'+$(this).val()+'').show();
				});
				// Uncheck all radion in the array
				$('#question'+q5ID+' tbody[id^="javatbd"]:hidden input.radio').attr('checked', 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.141 seconds
Donation Image