Welcome to the LimeSurvey Community Forum

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

Randomize the order of some items in array with last X options fixed

More
3 weeks 6 days ago #272506 by eperezpena
Hello This script allows you to randomly rotate the elements of an array while fixing the order of the last X elements (typically None, Don't Know, or No Answer).1) Create an array, set random order = TRUE2) In SOURCE MODE. Insert the following script.
Code:
[color=#000000]<script type='text/javascript'>[/color]
[color=#000000]$(document).ready(function() {[/color]
[color=#000000]var move_codes = [/color][color=#000000]["6", "7", "8", "9","96", "97", "99"];[/color]
[color=#000000]var baseId = "javatbd{SGQ}";[/color]
[color=#000000]var questionSelector = "#question{QID} .answers-list .answer-item:last-child";[/color]

[color=#000000]move_codes.forEach(function(code) {[/color]
[color=#000000]var move_element = baseId + code;[/color]
[color=#000000]$("#" + move_element).insertAfter(questionSelector);[/color]
[color=#000000]});[/color]
[color=#000000]});[/color]
modifying ONLY this"6", "7", "8", "9", "96", "97", "99"Which are the items that remain unrotated tested on LimeSurvey Community Edition Version 6.15.10+250901 and  LimeSurvey CE Version 3.17.5+190604

 

Please Log in to join the conversation.

More
3 weeks 4 days ago - 3 weeks 4 days ago #272547 by eperezpena
Sorry about that code:

<script type='text/javascript'>
$(document).ready(function() {
  var move_codes = ["6", "7", "8", "9","96", "97", "99"];
  var baseId = "javatbd{SGQ}";
  var questionSelector = "#question{QID} .answers-list .answer-item:last-child";

  move_codes.forEach(function(code) {
      var move_element = baseId + code;
      $("#" + move_element).insertAfter(questionSelector);
  });
});
</script>
 
Last edit: 3 weeks 4 days ago by eperezpena. Reason: For unwanted color tags in every line

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose