- Posts: 2
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
Please Log in to join the conversation.
<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 each array row exclusive function excludeOpt (qID) { var thisQuestion = $('#question'+qID) // Add some classes to the checkbox cells $('td.checkbox-item', thisQuestion).addClass('normal-item'); $('tr.subquestion-list', thisQuestion).each(function(i) { $('.normal-item:last', this).removeClass('normal-item').addClass('exlusive-item') }); // A listener on the checkboxes $('input[type="checkbox"]', thisQuestion).on('change', function (event) { handleExclusive($(this).closest('td')); }); function handleExclusive(thisCell) { var thisRow = $(thisCell).closest('tr'); // Uncheck the appropriate boxes in a row if ($(thisCell).hasClass('normal-item')) { $('.exlusive-item input[type="checkbox"]', thisRow).prop('checked', false); } else { $('.normal-item input[type="checkbox"]', thisRow).prop('checked', false); } // Check conditions (relevance) $('td.checkbox-item', thisRow).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.
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
// Uncheck the appropriate boxes in a row if ($(thisCell).hasClass('normal-item')) { $('.exclusive-item1 input[type="checkbox"]', thisRow).prop('checked', false); $('.exclusive-item2 input[type="checkbox"]', thisRow).prop('checked', false); } else { $('.normal-item input[type="checkbox"]', thisRow).prop('checked', false); } if ($(thisCell).hasClass('exclusive-item1')) { $('.exclusive-item2 input[type="checkbox"]', thisRow).prop('checked', false); } if ($(thisCell).hasClass('exclusive-item2')) { $('.exclusive-item1 input[type="checkbox"]', thisRow).prop('checked', false); }
Please Log in to join the conversation.
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ var exclusiveNumber = 2; var thisQuestion = $('#question{QID}'); // Add some classes to the checkbox cells $('td.checkbox-item', thisQuestion).addClass('normal-item'); $('tr.subquestion-list', thisQuestion).each(function(i) { $('td.checkbox-item', this).slice('-'+exclusiveNumber+'').removeClass('normal-item').addClass('exclusive-item'); }); // Listener on the checkboxes $('td.checkbox-item :checkbox', thisQuestion).on('change', function(e){ if($(this).is(':checked')) { var thisRow = $(this).closest('tr'); var thisCell = $(this).closest('td'); // Identify checkbox items to uncheck var excludedItems = $('td.exclusive-item', thisRow); if ($(thisCell).hasClass('exclusive-item')) { excludedItems = $('td.checkbox-item', thisRow).not(thisCell); } // Uncheck the boxes $(excludedItems).each(function(i) { $('input[type="hidden"]', this).val(''); $(':checkbox', this).prop('checked', false).trigger('change'); }); } }); }); </script>
Please Log in to join the conversation.