- Posts: 2
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
Please Log in to join the conversation.
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ randomArrayNumCols2({QID}); }); // A function to randomize columns in an array-numbers question leaving the last column in place function randomArrayNumCols2(qID){ var thisQuestion = $('#question'+qID); // Index the array columns and identify the last column $('table.subquestion-list tr', thisQuestion).each(function(i) { $('> *', this).each(function(i) { $(this).attr('data-index', i); }); $('> *:last', this).addClass('last-item'); }); // Create an array of the columns var columns = []; $('table.subquestion-list tr[id^="javatbd"]:eq(0) td.answer-item', thisQuestion).each(function(i) { columns.push($(this).attr('data-index')); }); // Shuffle the columns array columns = $.shuffle(columns); // Reposition the row elements $('table.subquestion-list tr', thisQuestion).each(function(i) { var thisRow = $(this); $(columns).each(function(i, val) { thisRow.append($('[data-index="'+val+'"]', thisRow)); thisRow.append($('.col-no-answer', thisRow)); }); thisRow.append($('.last-item', thisRow)); }); } // A function to shuffle elements or contents of arrays (function($){ $.fn.shuffle = function() { return this.each(function(){ var items = $(this).children(); return (items.length) ? $(this).html($.shuffle(items)) : this; }); } $.shuffle = function(arr) { for( var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x ); return arr; } })(jQuery); </script>
<script type="text/javascript" data-author="Tony Partner"> $(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('normal-item'); $('tr.subquestion-list', thisQuestion).each(function(i) { $('.normal-item:last', this).removeClass('normal-item').addClass('exclusive-item') }); // A listener on the checkboxes $('input[type="checkbox"]', thisQuestion).on('change', function (event) { handleExclusive($(this)); }); function handleExclusive(thisInput) { var thisCell = $(thisInput).closest('td'); var thisRow = $(thisCell).closest('tr'); $('input[type="checkbox"]', thisRow).prop('disabled', false); if(thisInput.is(':checked')) { // Uncheck the appropriate boxes in a row if ($(thisCell).hasClass('normal-item')) { $('.exclusive-item input[type="hidden"]', thisRow).val(''); $('.exclusive-item input[type="checkbox"]', thisRow).prop('checked', false); } else { $('.normal-item input[type="hidden"]', thisRow).val(''); $('.normal-item input[type="checkbox"]', thisRow).prop('checked', false).prop('disabled', true); } // 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>
Please Log in to join the conversation.
Please Log in to join the conversation.