- Posts: 38
- Thank you received: 2
Ask the community, share ideas, and connect with other LimeSurvey users!
function sortOptions(qID) { // Identify this question var thisQuestion = $('#question'+qID); // Create an array of subquestions var subQsArr = new Array(); $('li.answer-item', thisQuestion).each(function(i) { var thisString = $(this).find('.answertext').text()+'---'+$(this).attr('id'); subQsArr.push(thisString); }); // Sort the array subQsArr.sort(); // Repostion the subquestions in the sorted order $(subQsArr).each(function(i, val) { var thisID = val.split('---')[1]; $('li.answer-item:eq(0)', thisQuestion).parent().append($('#'+thisID)); }); }
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { sortOptions({QID}); }); </script>
function sortOptions(qID) { // Identify this question var thisQuestion = $('#question'+qID); // Create an array of subquestions var subQsArr = new Array(); $('li.answer-item', thisQuestion).each(function(i) { var thisString = $(this).find('.answertext').text()+'---'+$(this).attr('id'); subQsArr.push(thisString); }); // Sort the array subQsArr.sort(); // Repostion the subquestions in the sorted order $(subQsArr).each(function(i, val) { var thisID = val.split('---')[1]; $('li.answer-item:eq(0)', thisQuestion).parent().append($('#'+thisID)); }); $('li.answer-item:eq(0)', thisQuestion).parent().append($('li.answer-item[id$="other"]', thisQuestion)); }
ymca wrote: Hi,
I've also tried that, but it didn't work for me.
Version 4.2.0+200422
tpartner wrote: Oh, yeah, forgot that. Use this as the function in template.js:
Code:function sortOptions(qID) { // Identify this question var thisQuestion = $('#question'+qID); // Create an array of subquestions var subQsArr = new Array(); $('li.answer-item', thisQuestion).each(function(i) { var thisString = $(this).find('.answertext').text()+'---'+$(this).attr('id'); subQsArr.push(thisString); }); // Sort the array subQsArr.sort(); // Repostion the subquestions in the sorted order $(subQsArr).each(function(i, val) { var thisID = val.split('---')[1]; $('li.answer-item:eq(0)', thisQuestion).parent().append($('#'+thisID)); }); $('li.answer-item:eq(0)', thisQuestion).parent().append($('li.answer-item[id$="other"]', thisQuestion)); }
Wasn't expecting, was hoping.Joffm wrote: This thread started 6 years ago.
So, how can you expect a script, that was obviously created for a previous version (maybe 1.92 or 2.05) , to run.
Sure.You should file a bug report