- Posts: 17
- Thank you received: 2
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Call the exclude function using question ID excludeOpt({QID}); }); // A function to make the last option in a single-column multiple choice exclusive function excludeOpt(qID) { var thisQuestion = $('#question' + qID); // Add classes to the checkbox items $('input[type="checkbox"]', thisQuestion).each(function(i) { $(this).closest('li').addClass('normal-item'); }); // Mark the last checkbox as exclusive $('li.normal-item:last', thisQuestion).removeClass('normal-item').addClass('exclusive-item'); // A listener on the checkboxes $('input[type="checkbox"]', thisQuestion).on('change', function(event) { handleExclusive($(this).closest('li')); }); function handleExclusive(thisItem) { // Uncheck the appropriate boxes if ($(thisItem).hasClass('normal-item')) { $('.exclusive-item input[type="checkbox"]', thisQuestion).prop('checked', false); } else { $('.normal-item input[type="checkbox"]', thisQuestion).prop('checked', false); } // Check conditions (relevance) $('li.checkbox-item', thisQuestion).each(function(i) { var thisValue = ''; if ($('input[type="checkbox"]', this).is(':checked')) { thisValue = 1; } var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, ''); $('input[type="hidden"]', this).attr('value', thisValue); fixnum_checkconditions(thisValue, thisSGQA, 'hidden'); }); } } </script>
Please Log in to join the conversation.