- Posts: 419
- Thank you received: 34
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var qID = {QID}; var thisQuestion = $('#question'+qID); // Build an array of the sub-question texts var sqTexts = []; $('.label-text', thisQuestion).each(function(i) { sqTexts.push($.trim($(this).text())); }); // Sort the array sqTexts.sort(); // Insert the sub-questions in sorted order $(sqTexts).each(function(i, value) { $('.label-text', thisQuestion).filter(function(e) { return $.trim($(this).text()) === value; }).closest('.answer-item').parent().appendTo($('.multiple-choice-container', thisQuestion)); }); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var qID = {QID}; var thisQuestion = $('#question'+qID); // Define column and items counts var itemsCount = $('.answer-item', thisQuestion).length; var columnsCount = $('.multiple-choice-container div.row', thisQuestion).length; if(columnsCount > 1) { var maxPerColumn = $('.multiple-choice-container div.row:eq(0) .answer-item', thisQuestion).length; } // Build an array of the sub-question texts var sqTexts = []; $('.label-text', thisQuestion).each(function(i) { sqTexts.push($.trim($(this).text())); }); // Sort the array sqTexts.sort(); // Insert the sub-questions in sorted order var currentCount = 1; var columnNumber = 0; $(sqTexts).each(function(i, value) { if(columnsCount < 1) { $('.label-text', thisQuestion).filter(function(e) { return $.trim($(this).text()) === value; }).closest('.answer-item').parent().appendTo($('.multiple-choice-container', thisQuestion)); } else { $('.label-text', thisQuestion).filter(function(e) { return $.trim($(this).text()) === value; }).closest('.answer-item').parent().appendTo($('.multiple-choice-container div.row:eq('+columnNumber+')', thisQuestion)); currentCount++; if(currentCount > maxPerColumn) { currentCount = 1; columnNumber++; } } }); }); </script>