Welcome to the LimeSurvey Community Forum

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

randomize X-Scale

  • mana
  • mana's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 10 months ago #135736 by mana
randomize X-Scale was created by mana
hi
how can i randomize X-Scale in array number ?
unfortunately LS default it's only randomized Y-Scale.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 10 months ago #135740 by tpartner
Replied by tpartner on topic randomize X-Scale
It can only be done with JavaScript. LimeSurvey version?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • mana
  • mana's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 10 months ago #135750 by mana
Replied by mana on topic randomize X-Scale on array number
thanks for help

my LimeSurvey Version : 2.06+ , Build 160129
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 10 months ago #135794 by tpartner
Replied by tpartner on topic randomize X-Scale on array number
Set up your survey to use JavaScript and add this script to the source of the array question:

Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function() {  
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Define a columns array
    var columnsArr = [];
 
 
    // Loop through the question rows
    $('table.subquestions-list tr', thisQuestion).each(function(i) {
      var rowIndex = i;
 
      // Loop through the row cells
      $('> *', this).each(function(i){
        // Assign column-specific classes
        $(this).addClass('column-'+i+'');
        $(this).attr('data-column', i);
 
        // Load the columns array 
        if(rowIndex == 0 &amp;&amp; i > 0) {
          columnsArr.push(i);
        }
      });
    });
 
    // Shuffle the columns array
    shuffleArray(columnsArr);
 
    // Insert the cells in the shuffled order
    $('table.subquestions-list tr', thisQuestion).each(function(i) {
 
      var thisRow = $(this);
 
      $(columnsArr).each(function(i){
        $(thisRow).append($('[data-column="'+this+'"]', thisRow));
      });
    });
 
  });
 
  function shuffleArray(array) {
    for (var i = array.length - 1; i > 0; i--) {
      var j = Math.floor(Math.random() * (i + 1));
      var temp = array[i];
      array[i] = array[j];
      array[j] = temp;
    }
    return array;
  }
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...-2-3.lss
File Size:17 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: mana
The topic has been locked.
  • mana
  • mana's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 10 months ago #135862 by mana
Replied by mana on topic randomize X-Scale on array number
wow
its work
thanks tony :) :) :)
The topic has been locked.
  • mana
  • mana's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 8 months ago #139368 by mana
Replied by mana on topic randomize X-Scale on array number
hi
Can you change the code for randomize X-Scale in Array by column ?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 8 months ago - 7 years 8 months ago #139379 by tpartner
Replied by tpartner on topic randomize X-Scale on array number
This code will randomize the columns in an array-by-column question as is but you can also do that with the "Random order" question setting.

Or, by "X-Scale" do you mean the answers, which is actually the Y-scale in an array-by-column?


Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 7 years 8 months ago by tpartner.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose