- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
tpartner wrote: Try this to make the last two columns exclusive:
Code:<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 $('table.question tbody td', thisQuestion).addClass('normalOpt'); $('table.question tbody tr', thisQuestion).each(function(i) { // Last two coluns are exclusive $('.normalOpt:last', this).removeClass('normalOpt').addClass('exlusiveOpt'); $('.normalOpt:last', this).removeClass('normalOpt').addClass('exlusiveOpt'); }); // A listener on the checkboxes $('table.question tbody td input[type=checkbox]', thisQuestion).change(function (event) { if($(this).is(':checked')) { // Set some vars var thisRow = $(this).closest('tr'); var thisCell = $(this).closest('td'); // Uncheck the appropriate boxes in the row if ($(thisCell).hasClass('normalOpt')) { // Non-exclusive $('.exlusiveOpt input[type=checkbox]', thisRow).each(function(i) { $(this).prop('checked', false); $(this).closest('td').find('input[type="hidden"]').attr('value', ''); }); } else { // Exclusive $('input[type=checkbox]', thisRow).not(this).each(function(i) { $(this).prop('checked', false); $(this).closest('td').find('input[type="hidden"]').attr('value', ''); }); } } }); } </script>