- Posts: 28
- 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() { var thisQuestion = $('#question{QID}') // Add column-specific classes $('tr.subquestion-list', thisQuestion).each(function(i) { $('th, td', this).each(function(i) { $(this).addClass('column-'+i).attr('data-column', i); }); }); // Add some classes to the checkbox cells $('td.checkbox-item', thisQuestion).addClass('normal-opt'); $('tr.subquestion-list:last td.checkbox-item', thisQuestion).removeClass('normal-opt').addClass('exclusive-opt'); // A listener on the checkboxes $('td.checkbox-item input[type="checkbox"]', thisQuestion).change(function (event) { handleExclusive($(this).closest('td')); }); function handleExclusive(thisCell) { var thisColumn = $(thisCell).attr('data-column'); var thisCheckBox = $('input[type="checkbox"]', thisCell); // Uncheck the appropriate boxes in a row $('.checkbox-item[data-column="'+thisColumn+'"] input[type="checkbox"]').prop('disabled', false); if ($(thisCell).hasClass('normal-opt') && $(thisCheckBox).is(':checked')) { $('.exclusive-opt[data-column="'+thisColumn+'"] input:hidden').val(''); $('.exclusive-opt[data-column="'+thisColumn+'"] input[type="checkbox"]').prop('checked', false); } else if ($(thisCheckBox).is(':checked')) { $('.normal-opt[data-column="'+thisColumn+'"] input:hidden').val(''); $('.normal-opt[data-column="'+thisColumn+'"] input[type="checkbox"]').prop('checked', false).prop('disabled', true); } // Check conditions (relevance) $('td.checkbox-item[data-column="'+thisColumn+'"]').each(function(i) { var thisValue = ''; var itemCheckBox = $('input[type="checkbox"]', this); var thisSGQA = $(itemCheckBox).attr('id').replace(/cbox_/, ''); var aelt = $('#answer'+thisSGQA); fixnum_checkconditions($(aelt).val(), thisSGQA, 'hidden'); checkconditions($(itemCheckBox).attr('value'), $(itemCheckBox).attr('name'), $(itemCheckBox).attr('type')) }); } }); </script>