- Posts: 34
- Thank you received: 1
Ask the community, share ideas, and connect with other LimeSurvey users!
<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>