- Posts: 10248
- Thank you received: 3645
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // The number of answers to be fixed at the end of the list var fixedAnswers = 2; // Identify this question var qID = {QID}; // Find the number of answers var ansCount = $('#question'+qID+' .answer-item').length; // Place the last n answers created at the end of the list var fixedIndex = fixedAnswers - 1; for (var i=0; i<fixedAnswers; i++) { var answerItem = $('.answer-item[id^="javatbd"][id$="X'+qID+(ansCount-fixedIndex)+'"]'); if($('#question'+qID).hasClass('multiple-opt')) { $(answerItem).closest('.subquestion-list').append($(answerItem).parent()); } else { $(answerItem).closest('.answers-list').append(answerItem); } fixedIndex--; } }); </script>
function keepPos(SGQ,posArr){ var qtype = ''; var qid = SGQ.split('X')[2]; var $thisq = $('#question'+qid+''); if($thisq.hasClass('multiple-opt')){ qtype = 'multiple-opt'; }else if($thisq.hasClass('list-radio')){ qtype = 'list-radio'; } for (var i = posArr.length - 1; i >= 0; --i) { var thisPair = posArr[i].split('|'); var $allAnsItems = ''; var $thisAnsItem = ''; if(qtype == 'multiple-opt'){ $thisAnsItem = $('#javatbd'+SGQ+''+thisPair[0]+'').parent(); $allAnsItems = $('.answer-item',$thisq).parent(); }else if(qtype == 'list-radio'){ $thisAnsItem = $('#javatbd'+SGQ+''+thisPair[0]+''); $allAnsItems = $('.answer-item',$thisq); } $allAnsItems.eq(thisPair[1] - 1).after($thisAnsItem); } }
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { keepPos('{SGQ}',['SQ006|6','SQ007|7']) // keepPos('{SGQ}',['code|position','code|position']) }); </script>