If, for example, you have:
- Question codes
q1, q2, q3 for your existing questions
- Question code
qHidden for the new multiple-choice question
- Answer/sub-question codes 1, 2, 3, 4 for ALL questions
Placing a script like this in the source of the new multiple-choice will hide it and toggle the check-boxes according to the q1 and q2 answers. If you set q3 to be filtered by qHidden, the appropriate rows will be displayed.
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Identify this question
var thisQuestion = $('#question{QID}');
// Hide this question
thisQuestion.hide();
// Get the previous answers
var q1Answer = {q1};
var q2Answer = {q2};
// Reset the checkboxes
$('input[type="checkbox"]', thisQuestion).prop('checked', false);
$('li.question-item input[type="hidden"]', thisQuestion).val('');
// Toggle the appropriate checkboxes
switch(q1Answer) {
case 1:
$('input[type="checkbox"]:eq(0)', thisQuestion).prop('checked', true);
$('input[type="checkbox"]:eq(0)', thisQuestion).nextAll('input[type="hidden"]').val('Y');
$('input[type="checkbox"]:eq(1)', thisQuestion).prop('checked', true);
$('input[type="checkbox"]:eq(1)', thisQuestion).nextAll('input[type="hidden"]').val('Y');
break;
case 2:
$('input[type="checkbox"]:eq(0)', thisQuestion).prop('checked', true);
$('input[type="checkbox"]:eq(0)', thisQuestion).nextAll('input[type="hidden"]').val('Y');
break;
case 3:
$('input[type="checkbox"]:eq(1)', thisQuestion).prop('checked', true);
$('input[type="checkbox"]:eq(1)', thisQuestion).nextAll('input[type="hidden"]').val('Y');
break;
}
switch(q2Answer) {
case 1:
$('input[type="checkbox"]:eq(2)', thisQuestion).prop('checked', true);
$('input[type="checkbox"]:eq(2)', thisQuestion).nextAll('input[type="hidden"]').val('Y');
$('input[type="checkbox"]:eq(3)', thisQuestion).prop('checked', true);
$('input[type="checkbox"]:eq(3)', thisQuestion).nextAll('input[type="hidden"]').val('Y');
break;
case 2:
$('input[type="checkbox"]:eq(2)', thisQuestion).prop('checked', true);
$('input[type="checkbox"]:eq(2)', thisQuestion).nextAll('input[type="hidden"]').val('Y');
break;
case 3:
$('input[type="checkbox"]:eq(3)', thisQuestion).prop('checked', true);
$('input[type="checkbox"]:eq(3)', thisQuestion).nextAll('input[type="hidden"]').val('Y');
break;
}
// Fire the checkconditions() function for filtering
$('input[type="checkbox"]', thisQuestion).each(function(i) {
checkconditions(this.value, this.name, this.type);
});
});
</script>
Here's a small sample survey: