- Posts: 14
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // The Q2 options relevant to the Q1 options teacherLists = { C1 : 'T1,T3,T5', C2 : 'T1,T2,T3,T4', C3 : 'T2,T3,T4,T5', C4 : 'T1,T4,T6', }; // Identify the questions var q1ID = '{QID}'; var q1 = $('#question'+q1ID+''); var q2 = $(q1).nextAll('.list-radio:eq(0)'); var q2ID = $(q2).attr('id').split('question')[1]; // Find the initially checked option in Q1 (if any) var q1Ans = ''; if($('input.radio:checked', q1).length > 0) { q1Ans = $('input.radio:checked', q1).attr('value'); } // Initially Hide/Show the appropriate teachers showTeachers(q1Ans); // Click events on Q1 radios $('input.radio', q1).click(function() { var value = $(this).attr('value'); // Q1 has been changed if(value != q1Ans) { q1Ans = value; // Clear the Q2 answer $('input.radio', q2).attr('checked', false) // Show the appropriate teachers showTeachers(q1Ans); } }); // A function to show the appropriate teachers function showTeachers(q1Ans) { // Hide all of the teachers $('li[id^="javatbd"]', q2).hide(); // Now show the appropriate ones if(q1Ans != '') { $(teacherLists[q1Ans].split(',')).each(function(i){ $('input.radio[id$="'+q2ID+this+'"]').closest('li').show(); }); } } }); </script>
var q2 = $(q1).nextAll('.list-radio:eq(0)');
var q2 = $(q1).nextAll('.multiple-opt:eq(0)');
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // The Q2 options relevant to the Q1 options teacherLists = { C1 : 'T1,T3,T5', C2 : 'T1,T2,T3,T4', C3 : 'T2,T3,T4,T5', C4 : 'T1,T4,T6', }; // Identify the questions var q1ID = '{QID}'; var q1 = $('#question'+q1ID+''); var q2 = $(q1).nextAll('.multiple-opt:eq(0)'); var q2ID = $(q2).attr('id').split('question')[1]; // Find the initially checked option in Q1 var q1Ans = ''; if($('input.radio:checked', q1).length > 0) { q1Ans = $('input.radio:checked', q1).attr('value'); } // Initially Hide/Show the appropriate teachers showTeachers(q1Ans); // Click events on Q1 radios $('input.radio', q1).click(function() { var value = $(this).attr('value'); // Q1 has been changed if(value != q1Ans) { q1Ans = value; // Clear the Q2 answer $('input.checkbox', q2).attr('checked', false) // Show the appropriate teachers showTeachers(q1Ans); } }); // A function to show the appropriate teachers function showTeachers(q1Ans) { // Hide all of the teachers $('li[id^="javatbd"]', q2).hide(); // Now show the appropriate ones if(q1Ans != '') { $(teacherLists[q1Ans].split(',')).each(function(i){ $('input.checkbox[id$="'+q2ID+this+'"]').closest('li').show(); }); } } }); </script>