Welcome to the LimeSurvey Community Forum

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

Showing answers in reverse order based on random number

  • paulfiner
  • paulfiner's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
7 years 1 month ago #147494 by paulfiner
I have a radio list question with 6 answers
1 - dislike very much
2
3
4
5 - like very much
Don't know

I would like to reverse the scale for the first 5 answers if a random number (between 1 and 2) is a 2
I'm fairly sure this can be done with Javascript but it's beyond my knowledge!
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 1 month ago #147500 by holch
Easiest: create a second questions with the reverse order, show each question depending on the random number.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • paulfiner
  • paulfiner's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
7 years 1 month ago #147505 by paulfiner
I did think about doing it that way but I quite a few questions in the survey that need this functionality and it would also avoid having to merge the 2 questions at the analysis stage.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 1 month ago #147512 by holch
I agree that it adds an additional level of work to merge the 2 questions, but in Excel this can be done with a formula in an additional column quite quickl (and I am sure software like SPSS offer something to solve this) and it is probably a lot more secure than doing it with Javascript (you don't need any additional code, only LS own features).

But I am sure that Tpartner or someone might have a Javascript solution. Just I can't really help with that.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • paulfiner
  • paulfiner's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
7 years 1 month ago - 7 years 1 month ago #147570 by paulfiner
If anyone is interested in a solution to this which can help to remove any bias from scaled questions, I came up with a small javascript solution which seems to work.
Basically, it generates a random number between 1 and 2 and if it is a 2, the scales are reversed.
In my case, I had a 'Don't know' option at the end which needed to remain fixed.

Here is the code:
Code:
<script type='text/javascript'>
$(document).ready(function() {
var randNum = Math.floor((Math.random() * 2)+1);
if (randNum == 2) { 
  var place_before="javatbd{SGQ}"+6;
  for (var i=5; i>0; i--) {
     var move_element="javatbd{SGQ}"+i;
     $("#"+move_element).insertBefore("#"+place_before);
  }
}
});
</script>
For some reason the code tags don't seem to be working??
Last edit: 7 years 1 month ago by DenisChenu.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose