Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Partially randomized answers (list radio type) in 2.50

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 4 months ago #160907 by tpartner
In that version, the IDs have changed slightly - use this script:

Code:
<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>

Sample survey attached:

File Attachment:

File Name: limesurvey...9124.lss
File Size:19 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: blocka
The topic has been locked.
More
6 years 4 months ago #160908 by blocka
Awesome! Thanks so much, I've confirmed it works :-)
The topic has been locked.
More
6 years 4 months ago #161249 by first
I am back on forums after a long time :) . Here is my try:

This will go in template.js
Code:
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);
  }
 
}

and this will go in question text.
Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function() {
    keepPos('{SGQ}',['SQ006|6','SQ007|7']) //  keepPos('{SGQ}',['code|position','code|position'])
  });
</script>

tested with Version 2.72.5 and list-radio and multi-checkbox.

Survey Designer and Programmer
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 4 months ago #161257 by tpartner
How is this different or better?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose