- Posts: 65
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify this question var thisQuestion = $('#question{QID}'); // Create an array of dropdown option text values var optionTexts = []; $('select.form-control:eq(0) option', thisQuestion).each(function(i) { if($(this).val() != '') { optionTexts.push($.trim($(this).text())); } }); // Sort the array optionTexts.sort(function (a, b) { return a.toLowerCase().localeCompare(b.toLowerCase()); }); //Loop through the option texts and insert the corresponding drop-down options $.each(optionTexts, function(key, val) { $('select.form-control:eq(0) option', thisQuestion).filter(function() { return $.trim($(this).text()).toLowerCase() == val.toLowerCase(); }).appendTo($('select.form-control:eq(0)', thisQuestion)); }); }); </script>