Welcome to the LimeSurvey Community Forum

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

Combine two array questions into one with array filter functionality

More
8 years 2 months ago #129898 by ervit
Hi,

I have two multiple choice list questions:
* Q1 is a Multiple choice list on page 1 (Group 1);
* Q2 is a Multiple choice with comments on page 2 (Group 2)).

I need to ask another multiple choice question Q3 on page 2 (Group 2), that would show a combination of selections from both Q1 and Q2. This Q3 will then be used as a (hidden) array filter for other questions. So, my questions:

1. Can it be done with built-in array filter functionality somehow?

My guess is that it CAN'T be done, so:

2. I tried using JavaScript and while I was able to "tick" the boxes in Q3 using answers from Q2 (with some javascript inside Q3), I can't do the same for Q2 answers. My javascript fails executing the following line and as a result the whole code section fails:
Code:
//this fails
var dir = '{Q2_SQ001.NAOK}';

This is the code inserted into Q2 on Page 2 (Group 2):
Code:
<script type="text/javascript" charset="utf-8">  
 $(document).ready(function() {
 
  // Identify this question
  var thisQuestion = $('#question{QID}');
 
  // Assign event function to comment boxes
  $('input[type="text"]', thisQuestion).on('change', function() {
 
     var targetQuestion = $('#question3');  // this is Q3 reference
     var dir = '{Q2_SQ001.NAOK}';
  });
});
 
</script>

It seems the problem is in Q2 being on the same page where I try to run this code (i.e. same page as Q3), but I have no ideas for alternatives. I can't put Q2 and Q3 on separate pages.
The topic has been locked.
More
8 years 2 months ago #129925 by ervit
I did it differently. Instead of trying to read the {Expression Manager variable} into javascript (which was failing for whatever reason), I decided to check the checkbox status directly:
Code:
<script type="text/javascript" charset="utf-8">  
 $(document).ready(function() {
 
  // Identify this question
  var thisQuestion = $('#question{QID}');
 
  // Assign event function to checkboxes
  $('input[type="text"]', thisQuestion).on('change', function() {
 
     var targetQuestion = $('#question1831'); //Question 3
 
     if ($('input.checkbox:eq(0)', thisQuestion).is(':checked')) {
 
        $('input.checkbox:eq(6)', targetQuestion).attr('checked', true);
  $('input.checkbox:eq(6)', targetQuestion).parent().find('input[type="hidden"]').val('Y');
 
        };
 
 
  });
});
 
</script>

Hope this helps someone else
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose