Welcome to the LimeSurvey Community Forum

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

Coding things for Best / Worst Scaling

  • ethridge123a
  • ethridge123a's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 11 months ago #195984 by ethridge123a
Coding things for Best / Worst Scaling was created by ethridge123a
I am completely new to this platform and am trying to learn about the capabilities of Lime Survey.

I am wondering if it is possible to set up questions that allow for best / worst choices from a list. By this, I mean rather than standard Likert scale questions, I mean the ability to list, say, 5 companies or brands and ask the respondent to choose their favorite and least favorite from the list.

Is anyone aware of an example where this has been done.

(My apologies if this is a naive or trivial question. I am new.)
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months ago #195985 by Joffm
Replied by Joffm on topic Coding things for Best / Worst Scaling
Hi,
first you may do a search here for "maxdiff".

As you did not mention the LimeSurvey version you are using,
here a solution that works in 3.x. (and 4.x.)
Use an array by column and enter this into the question text (source)
Code:
<script type="text/javascript" charset="utf-8">     
function maxDiff(qID, randomize) {
 
  // Identify some elements
  var thisQuestion = $('#question'+qID);
  var thisTable = $('table.subquestion-list:eq(0)', thisQuestion);
 
  // Assign a new question class
  $(thisQuestion).addClass('max-diff-array');
 
  // Move the columns
   $('thead tr:eq(0)', thisTable).prepend($('thead tr:eq(0) th:eq(1)', thisTable));
  $('tr.answers-list', thisTable).each(function(i){
  $('td.answer-item:eq(0)', this).prependTo(this);
  });
 
  // Random rows
  if(randomize) {
    var rowsArr = [];
    $('tr.answers-list', thisTable).each(function(i){
      $(this).attr('data-index', i);
      rowsArr.push(i);
    });
    shuffleArray(rowsArr);
    $(rowsArr).each(function(i){
      $('tbody', thisTable).append($('tr[data-index="'+this+'"]', thisTable));
    });
  }
 
  // Prevent clicking twice in the same row
  $('input[type="radio"]', thisQuestion).on('click', function () {
 
    $('input[type="radio"]', thisQuestion).prop('disabled', false);
    $('input[type="radio"]:checked', thisQuestion).each(function(i) {
      var thisRow = $(this).closest('tr.answers-list');
      $('input[type="radio"]', thisRow).not(this).prop('disabled', true);
    });
  });
 
  // Fix up the row classes
  var rowClass = 1;
  $('tr.answers-list', thisTable).each(function(i) {
    $(this).addClass('array'+(2-(i%2)));
  });
}
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;
}
 
  $(document).ready(function(){
    // Call the maxDiff() function
    // Set the second parameter to true for randomized rows
    maxDiff({QID}, true);
  });
</script>
<style type="text/css">.ls-answers tbody .answertext {
    text-align: center;
}
</style>



Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose