- Posts: 34
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
Please Log in to join the conversation.
Please Log in to join the conversation.
I would like to implement this code on version 2.73.1
Please Log in to join the conversation.
<script type="text/javascript" data-author="DBEL"> $(document).ready(function() { // Call the exclude function using question ID excludeOpt({QID}); }); // A function to set up exclusivity function excludeOpt(qID) { var thisQuestion = $('#question' + qID); // Set up exclusivity for each row thisQuestion.find('tr.subquestion-list').each(function() { setupRowExclusivity($(this)); }); // A listener on the checkboxes thisQuestion.find('input[type="checkbox"]').on('change', function(event) { handleExclusive($(this)); }); function setupRowExclusivity(row) { row.find('td.checkbox-item').each(function(index) { if (index === 1) { $(this).addClass('exclusive-item'); } else if (index === 0) { $(this).addClass('neutral-item'); } else { $(this).addClass('normal-item'); } }); $('.exclusive-item input[type="hidden"]', row).val(''); // Initially disable the normal items $('.normal-item input[type="checkbox"]', row).prop('disabled', true); } function handleExclusive(thisInput) { var thisCell = thisInput.closest('td'); var thisRow = thisInput.closest('tr'); if ($(thisCell).hasClass('neutral-item')) { // Do nothing or add specific logic for the neutral item } else if ($(thisCell).hasClass('exclusive-item')) { // If exclusive item is checked, enable/disable normal items accordingly var normalItems = $('.normal-item input[type="checkbox"]', thisRow); normalItems.prop('disabled', !thisInput.is(':checked')); if (!thisInput.is(':checked')) { normalItems.prop('checked', false); } } // Check conditions (relevance) $('td.checkbox-item', thisRow).each(function() { var thisValue = $('input[type="checkbox"]', this).is(':checked') ? 1 : ''; var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, ''); $('input[type="hidden"]', this).attr('value', thisValue); fixnum_checkconditions(thisValue, thisSGQA, 'hidden'); }); } } </script>
Please Log in to join the conversation.
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}') // Add some classes to the checkbox cells // 3rd children (answer column 2) $('td.checkbox-item:nth-child(3)', thisQuestion).addClass('exclusive-item'); // 4th and above children (answer columns greater than 2) $('td.checkbox-item:nth-child(n+4)', thisQuestion).addClass('excluded-item'); // A listener on the exclusive checkboxes $('.exclusive-item input:checkbox', thisQuestion).on('change', function (event) { handleExclusive($(this)); }); // Returning to page $('.exclusive-item input:checkbox', thisQuestion).each(function (i) { handleExclusive($(this)); }); function handleExclusive(thisInput) { var thisCell = $(thisInput).closest('td'); var thisRow = $(thisCell).closest('tr'); if(thisInput.is(':checked')) { // Enable the excluded checkboxes $('.excluded-item input:checkbox', thisRow).prop('disabled', false); } else { // Uncheck the excluded boxes in a row $('.excluded-item input[type="hidden"]', thisRow).val(''); $('.excluded-item input:checkbox', thisRow).prop('checked', false).trigger('change').prop('disabled', true); } } }); </script>
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.