- Posts: 153
- Thank you received: 8
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify this question var thisQuestion = $('#question{QID}'); // Listener on the checkboxes $('input:checkbox', thisQuestion).on('change', function(e) { if($(this).is(':checked')) { $('input:checkbox', thisQuestion).not(this).prop('checked', false).trigger('change'); } }); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var thisQuestion = $('#question{QID}'); // Add some classes var sqCount = $('.question-item', thisQuestion).length; $('.question-item:eq('+(sqCount-22)+')', thisQuestion).addClass('non-exclusive-item'); // first item $('.question-item:eq('+(sqCount-21)+')', thisQuestion).addClass('non-exclusive-item'); // 2nd item $('.question-item:eq('+(sqCount-20)+')', thisQuestion).addClass('non-exclusive-item'); $('.question-item:eq('+(sqCount-18)+')', thisQuestion).addClass('non-exclusive-item'); $('.question-item:eq('+(sqCount-17)+')', thisQuestion).addClass('non-exclusive-item'); $('.question-item:eq('+(sqCount-16)+')', thisQuestion).addClass('non-exclusive-item'); $('.question-item:eq('+(sqCount-14)+')', thisQuestion).addClass('non-exclusive-item'); $('.question-item:eq('+(sqCount-13)+')', thisQuestion).addClass('non-exclusive-item'); $('.question-item:eq('+(sqCount-12)+')', thisQuestion).addClass('non-exclusive-item'); $('.question-item:eq('+(sqCount-10)+')', thisQuestion).addClass('non-exclusive-item'); $('.question-item:eq('+(sqCount-9)+')', thisQuestion).addClass('non-exclusive-item'); $('.question-item:eq('+(sqCount-8)+')', thisQuestion).addClass('non-exclusive-item'); $('.question-item:eq('+(sqCount-6)+')', thisQuestion).addClass('non-exclusive-item'); $('.question-item:eq('+(sqCount-5)+')', thisQuestion).addClass('non-exclusive-item'); $('.question-item:eq('+(sqCount-3)+')', thisQuestion).addClass('non-exclusive-item'); $('.question-item:eq('+(sqCount-2)+')', thisQuestion).addClass('non-exclusive-item'); // // 2nd last item $('.question-item:eq('+(sqCount-1)+')', thisQuestion).addClass('non-exclusive-item'); // Last item // Handle exclusive items $('input[type="checkbox"]', thisQuestion).on('change', function(e) { if($(this).is(':checked') ) { var thisItem = $(this).closest('.question-item'); var actionItems = $('.question-item', thisQuestion).not($(thisItem)); if($(thisItem).hasClass('non-exclusive-item')) { actionItems = $('.exclusive-item', thisQuestion); } actionItems.each(function(i) { $('input[type="checkbox"]', this).prop('checked', false).trigger('change'); $('input:hidden', this).attr('value', ''); $('input[type="text"]', this).val('').trigger('keyup'); }); } }); $('input[type="text"]', thisQuestion).on('keyup change', function(e) { var thisInput = $(this); setTimeout(function() { $(thisInput).closest('.question-item').find('input[type="checkbox"]').trigger('change'); }, 200); }); }); </script>