- Posts: 35
- 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() { // Uncomment the line below to hide the question // $('#question{QID}').hide(); // Build an associative array of the answers var answers = { Q1:{Q1}, Q2:{Q2}, Q3:{Q3}, Q4:{Q4}, Q5:{Q5} } // Build an array of arrays with the qCode:answer pairs var sortedAnswers = []; for(var question in answers) { sortedAnswers.push([question, answers[question]]); } // Sort that array of arrays descending sortedAnswers.sort( function(a, b) { return b[1] - a[1] } ); // Build an array of the sorted qCodes var sortedQuestions = []; $(sortedAnswers).each(function(i) { sortedQuestions.push(this[0]); }); // Load the sorted qCodes into the question input $('#question{QID} input.text').val(sortedQuestions); }); </script>