- Posts: 54
- 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}'); var noAnswer = 99999; // Add some classes to the answer cells $('td.question-item', thisQuestion).addClass('normal-opt'); $('td.question-item:last-child', thisQuestion).removeClass('normal-opt').addClass('exlusive-opt') $('.exlusive-opt select', thisQuestion).hide(); $('.exlusive-opt', thisQuestion).append('<input type="checkbox" class="checkbox">'); $('.exlusive-opt select', thisQuestion).append('<option value="'+noAnswer+'">'+noAnswer+'</option>'); $('.normal-opt select', thisQuestion).on('change', function() { var thisRow = $(this).closest('tr.subquestions-list'); if($(this).val() != ''){ $('.exlusive-opt input[type=checkbox]', thisRow).prop('checked', false); $('.exlusive-opt select', thisRow).val(''); $('.exlusive-opt input[type="hidden"]', thisRow).attr('value', ''); } }); $('.exlusive-opt input[type="checkbox"]', thisQuestion).on('change', function(event) { var thisCell = $(this).closest('td.question-item'); var thisRow = $(this).closest('tr.subquestions-list'); if($(this).is(':checked')) { $('select', thisCell).val(noAnswer); $('input[type="hidden"]', thisCell).attr('value', noAnswer); $('.normal-opt select', thisRow).val(''); $('.normal-opt input[type="hidden"]', thisRow).attr('value', ''); } else { $('.exlusive-opt select', thisRow).val(''); $('.exlusive-opt input[type="hidden"]', thisRow).attr('value', ''); } }); $('.exlusive-opt input[type="hidden"]', thisQuestion).each(function(i) { var thisCell = $(this).closest('td.question-item'); if($(this).attr('value') == noAnswer) { $('input[type=checkbox]', thisCell).prop('checked', true); $('select', thisCell).val(noAnswer); } }); }); </script>