1)
Set up your survey to use JavaScript
.
2) Directly after Q1, add a multiple-choice question with the same sub-questions and codes as Q1 (we'll call this "qHidden").
3) Set Q2 (and any subsequent arrays) to be array-filtered by qHidden.
4) Add the following script to the source of the qHidden. This will:
- hide qHidden
- put a listener on the Q1 radios
- if a radio in column 1 of Q1 is clicked, the corresponding checkbox in qHidden is checked and the array filter handles the display of rows in Q2
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
// Identify the questions
var qHiddenID = ('{QID}');
var qHidden = $('#question'+qHiddenID);
var q1 = $(qHidden).prevAll('.array-flexible-row:eq(0)');
var q1ID = $(q1).attr('id').split('question')[1];
// Hide the hidden question
$(qHidden).css({
'position': 'absolute',
'left': '-999em'
});
// Add some column-specific classes to Q1
$('table.subquestions-list tr', q1).each(function(i){
$('> *', this).each(function(i){
$(this).addClass('column-'+i);
});
});
// Listener on Q1
$('input.radio', q1).change(function(event){
// Reset the hidden question
$('input.checkbox', qHidden).prop('checked', false);
$('li.question-item input[type="hidden"]', qHidden).val('');
// Check the appropriate boxes in the hidden question
$('.column-1 input.radio:checked', q1).each(function(i) {
var thisCode = $(this).attr('id').split('X'+q1ID)[1].split('-')[0];
$('input.checkbox[id$="X'+qHiddenID+thisCode+'"]', qHidden).prop('checked', true);
$('input.checkbox[id$="X'+qHiddenID+thisCode+'"]', qHidden).next('input[type="hidden"]').val('Y');
});
// Fire the array filter
$('input.checkbox', qHidden).each(function(i) {
checkconditions($(this).attr('value'), $(this).attr('name'), $(this).attr('type'));
});
});
});
</script>
Here's a working survey (with an additional array in a following group also filtered by qHidden). In this survey, I also added the following relevance to Q2 and Q3 so the whole question is hidden unless a radio in column 1 of Q1 is clicked:
Code:
CI1_SQ001 == 'A1' || CI1_SQ002 == 'A1' || CI1_SQ003 == 'A1'