- Posts: 136
- Thank you received: 4
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Define the maximum answers per column var maxAnswers = 1; // Identify this question var thisQuestion = $('#question{QID}'); // Index the array columns $('table.subquestion-list tr', thisQuestion).each(function(i) { $('> *', this).each(function(i) { $(this).attr('data-index', i); }); }); // Listener on the checkboxes $('input[type="checkbox"]', thisQuestion).on('change', function(e) { var thisIndex = $(this).closest('.answer-item').attr('data-index'); $('[data-index="'+thisIndex+'"] input[type="checkbox"]', thisQuestion).prop('disabled', false); // If max reached, disable unchecked inputs in this column if($('[data-index="'+thisIndex+'"] input[type="checkbox"]:checked', thisQuestion).length >= maxAnswers) { $('[data-index="'+thisIndex+'"] input[type="checkbox"]:not(:checked)', thisQuestion).prop('disabled', true); } }); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Define the maximum answers per row var maxAnswers = 3; // Identify this question var thisQuestion = $('#question{QID}'); // Listener on the checkboxes $('input[type="checkbox"]', thisQuestion).on('change', function(e) { var thisRow = $(this).closest('tr'); $('input[type="checkbox"]', thisRow).prop('disabled', false); // If max reached, disable unchecked inputs in this row if($('input[type="checkbox"]:checked', thisRow).length >= maxAnswers) { $('input[type="checkbox"]:not(:checked)', thisRow).prop('disabled', true); } }); }); </script>