- Posts: 10265
- Thank you received: 3648
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" data-author="Tony Partner"> $(document).ready(function() { var thisQuestion = $('#question{QID}'); // Add column and row specific classes $('tr.subquestion-list', thisQuestion).each(function(i) { var rowIndex = i; $('th, td', this).each(function(i) { $(this).addClass('column-'+i+' row-'+rowIndex).attr('data-column', i).attr('data-row', rowIndex); }); }); // Add some classes to the checkbox cells $('tr.subquestion-list .answer-item:nth-child(n+4)', thisQuestion).addClass('exclusive-item row-exclusive set-2').attr('data-set', 2); $('tr.subquestion-list .answer-item:not(.set-2)', thisQuestion).addClass('exclusive-item row-exclusive set-1').attr('data-set', 1); // A listener on the checkboxes $('.answer-item input[type="checkbox"]', thisQuestion).change(function (event) { handleExclusive($(this).closest('.answer-item')); }); function handleExclusive(thisCell) { var thisCheckBox = $(':checkbox', thisCell); if(thisCheckBox.is(':checked')) { var thisRow = $(thisCell).attr('data-row'); var thisColumn = $(thisCell).attr('data-column'); var thisSet = $(thisCell).attr('data-set'); var excludeCells = $('.answer-item[data-row="'+thisRow+'"]').not('[data-set="'+thisSet+'"]'); // Uncheck those items $(excludeCells).each(function(i) { $('input:hidden', this).val(''); $(':checkbox', this).prop('checked', false).trigger('change'); }); } } }); </script>
<script type="text/javascript" data-author="Tony Partner"> $(document).ready(function() { var thisQuestion = $('#question{QID}'); // Add column and row specific classes $('tr.subquestion-list', thisQuestion).each(function(i) { var rowIndex = i; $('th, td', this).each(function(i) { $(this).addClass('column-'+i+' row-'+rowIndex).attr('data-column', i).attr('data-row', rowIndex); }); }); // Add some classes to the checkbox cells $('.answer-item:nth-child(2), .answer-item:nth-child(3)', thisQuestion).addClass('exclusive-item row-exclusive set-1').attr('data-set', 1); $('.answer-item:nth-child(4)', thisQuestion).addClass('exclusive-item row-exclusive set-2').attr('data-set', 2); $('.answer-item:nth-child(5)', thisQuestion).addClass('exclusive-item row-exclusive set-3').attr('data-set', 3); // A listener on the checkboxes $('.answer-item input[type="checkbox"]', thisQuestion).change(function (event) { handleExclusive($(this).closest('.answer-item')); }); function handleExclusive(thisCell) { var thisCheckBox = $(':checkbox', thisCell); if(thisCheckBox.is(':checked')) { var thisRow = $(thisCell).attr('data-row'); var thisColumn = $(thisCell).attr('data-column'); var thisSet = $(thisCell).attr('data-set'); var excludeCells = $('.answer-item[data-row="'+thisRow+'"]').not('[data-set="'+thisSet+'"]'); // Uncheck those items $(excludeCells).each(function(i) { $('input:hidden', this).val(''); $(':checkbox', this).prop('checked', false).trigger('change'); }); } } }); </script>
<script type="text/javascript" data-author="Tony Partner"> $(document).ready(function() { var thisQuestion = $('#question{QID}'); // Add column and row specific classes $('tr.subquestion-list', thisQuestion).each(function(i) { var rowIndex = i; $('th, td', this).each(function(i) { $(this).addClass('column-'+i+' row-'+rowIndex).attr('data-column', i).attr('data-row', rowIndex); }); }); // Add some classes to the checkbox cells $('.answer-item:nth-last-child(1), .answer-item:nth-last-child(2)', thisQuestion).addClass('exclusive-item row-exclusive') // A listener on the checkboxes $('.answer-item input[type="checkbox"]', thisQuestion).change(function (event) { handleExclusive($(this).closest('.answer-item')); }); function handleExclusive(thisCell) { var thisCheckBox = $(':checkbox', thisCell); if(thisCheckBox.is(':checked')) { var thisRow = $(thisCell).attr('data-row'); var excludeCells = $('.answer-item.exclusive-item[data-row="'+thisRow+'"]'); if($(thisCell).hasClass('exclusive-item')) { excludeCells = $('.answer-item[data-row="'+thisRow+'"]').not(thisCell); } // Uncheck those items $(excludeCells).each(function(i) { $('input:hidden', this).val(''); $(':checkbox', this).prop('checked', false).trigger('change'); }); } } }); </script>