- Posts: 58
- Thank you received: 9
Ask the community, share ideas, and connect with other LimeSurvey users!
<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 $('td.checkbox-item', thisQuestion).addClass('normalOpt'); $('tr.subquestions-list', thisQuestion).each(function(i) { $('.normalOpt:last', this).removeClass('normalOpt').addClass('exlusiveOpt') }); // A listener on the checkbox cells $('td.checkbox-item', thisQuestion).click(function (event) { handleExclusive($(this)); }); // A listener on the checkboxes $('td.checkbox-item input[type="checkbox"]', thisQuestion).click(function (event) { handleExclusive($(this).closest('td')); }); function handleExclusive(thisCell) { var thisRow = $(thisCell).closest('tr'); // Uncheck the appropriate boxes in a row if ($(thisCell).hasClass('normalOpt')) { $('.exlusiveOpt input[type="checkbox"]', thisRow).attr('checked', false); } else { $('.normalOpt input[type="checkbox"]', thisRow).attr('checked', false); } // Check conditions (relevance) $('td.checkbox-item', thisRow).each(function(i) { var thisValue = ''; if($('input[type="checkbox"]', this).is(':checked')) { thisValue = 1; } var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, ''); $('input[type="hidden"]', thisRow).attr('value', 'thisValue'); fixnum_checkconditions(thisValue, thisSGQA, 'hidden'); }); } } </script>
<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 colExcludeOpt (qID) { var thisQuestion = $('#question'+qID) // Add some classes to the checkbox cells $('td.checkbox-item', thisQuestion).addClass('normalOpt'); $('tr.subquestions-list:last td.checkbox-item', thisQuestion).removeClass('normalOpt').addClass('exlusiveOpt') // And some column-specific attributes $('tr.subquestions-list', thisQuestion).each(function(i){ $('td.answer-item', this).each(function(i){ $(this).attr('data-column', i+1); }); }); // A listener on the checkbox cells $('td.checkbox-item', thisQuestion).click(function (event) { handleColExclusive($(this)); }); // A listener on the checkboxes $('td.checkbox-item input[type="checkbox"]', thisQuestion).click(function (event) { handleColExclusive($(this).closest('td')); }); function handleColExclusive(thisCell) { var thisColumn = $(thisCell).attr('data-column'); // Uncheck the appropriate boxes in a row if ($(thisCell).hasClass('normalOpt')) { $('.exlusiveOpt[data-column="'+thisColumn+'"] input[type="checkbox"]', thisQuestion).attr('checked', false); } else { $('.normalOpt[data-column="'+thisColumn+'"] input[type="checkbox"]', thisQuestion).attr('checked', false); } // Check conditions (relevance) $('td.checkbox-item[data-column="'+thisColumn+'"]', thisQuestion).each(function(i) { var thisValue = ''; if($('input[type="checkbox"]', this).is(':checked')) { thisValue = 1; } var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, ''); $('input[type="hidden"]', this).attr('value', 'thisValue'); fixnum_checkconditions(thisValue, thisSGQA, 'hidden'); }); } } </script>
<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 $('td.checkbox-item', thisQuestion).addClass('normalOpt'); $('tr.subquestions-list', thisQuestion).each(function(i) { $('.normalOpt:last', this).removeClass('normalOpt').addClass('exlusiveOpt') }); // A listener on the checkbox cells $('td.checkbox-item', thisQuestion).click(function (event) { handleExclusive($(this)); }); // A listener on the checkboxes $('td.checkbox-item input[type="checkbox"]', thisQuestion).click(function (event) { handleExclusive($(this).closest('td')); }); function handleExclusive(thisCell) { var thisRow = $(thisCell).closest('tr'); // Uncheck the appropriate boxes in a row if ($(thisCell).hasClass('normalOpt')) { $('.exlusiveOpt input[type="checkbox"]', thisRow).attr('checked', false); } else { $('.normalOpt input[type="checkbox"]', thisRow).attr('checked', false); } // Check conditions (relevance) $('td.checkbox-item', thisRow).each(function(i) { var thisValue = ''; if($('input[type="checkbox"]', this).is(':checked')) { thisValue = 1; } var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, ''); $('input[type="hidden"]', this).attr('value', 'thisValue'); fixnum_checkconditions(thisValue, thisSGQA, 'hidden'); }); } } </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var thisQuestion = $('#question{QID}') // Add column-specific classes $('tr.subquestion-list', thisQuestion).each(function(i) { $('th, td', this).each(function(i) { $(this).addClass('column-'+i).attr('data-column', i); }); }); // Add some classes to the checkbox cells $('td.checkbox-item', thisQuestion).addClass('normal-opt'); $('tr.subquestion-list:last td.checkbox-item', thisQuestion).removeClass('normal-opt').addClass('exclusive-opt'); // A listener on the checkboxes $('td.checkbox-item input[type="checkbox"]', thisQuestion).change(function (event) { handleExclusive($(this).closest('td')); }); function handleExclusive(thisCell) { var thisColumn = $(thisCell).attr('data-column'); var thisCheckBox = $('input[type="checkbox"]', thisCell); // Uncheck the appropriate boxes in a row $('.checkbox-item[data-column="'+thisColumn+'"] input[type="checkbox"]').prop('disabled', false); if ($(thisCell).hasClass('normal-opt') && $(thisCheckBox).is(':checked')) { $('.exclusive-opt[data-column="'+thisColumn+'"] input:hidden').val(''); $('.exclusive-opt[data-column="'+thisColumn+'"] input[type="checkbox"]').prop('checked', false); } else if ($(thisCheckBox).is(':checked')) { $('.normal-opt[data-column="'+thisColumn+'"] input:hidden').val(''); $('.normal-opt[data-column="'+thisColumn+'"] input[type="checkbox"]').prop('checked', false).prop('disabled', true); } // Check conditions (relevance) $('td.checkbox-item[data-column="'+thisColumn+'"]').each(function(i) { var thisValue = ''; var itemCheckBox = $('input[type="checkbox"]', this); var thisSGQA = $(itemCheckBox).attr('id').replace(/cbox_/, ''); var aelt = $('#answer'+thisSGQA); fixnum_checkconditions($(aelt).val(), thisSGQA, 'hidden'); checkconditions($(itemCheckBox).attr('value'), $(itemCheckBox).attr('name'), $(itemCheckBox).attr('type')) }); } }); </script>