Welcome to the LimeSurvey Community Forum

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

Randomizing a fixed pattern for attribute display

  • jimstarks
  • jimstarks's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 1 month ago #101820 by jimstarks
Hi all,

I've looked through the forum topics pretty extensively and haven't seen an answer to this, but feel free to redirect me if I've missed something.

I'm trying to randomize answer options, which I have seen covered here, but with two slight modifications...

1) In addition to keeping the Other and DK/NR options at the bottom of the list, I commonly need to keep certain responses together as a list (e.g. items 3 and 4 need to stay together in the rotation pattern).
2) I'd like to keep the same order for the randomized list across questions. The same list might appear 5 or 6 times for different questions.

I have no problem generating a series of randomization orders, but I don't know how to apply that to the displayed answer options. The one idea that does occur to me is to create a number of groups that are basically copies of the same questions with the responses rotated manually and then randomly choose one group to display. That seems like quite a bit of work, though, if there's a way to apply a pre-designed ordering vector.

Any thoughts? Thanks...JIM
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 1 month ago - 11 years 1 month ago #101832 by tpartner
These aren't "slight" modifications :)

Perhaps a workaround could be...

1) Randomize the answers of the first question (with the LS setting)
2) Use JavaScript to move the "fixed" answers to the appropriate places
3) Use JavaScript to create an array of the reordered answer codes and load it into a hidden question
4) In subsequent questions, recover the array (with Expression Manager or INSERTANS) and use JavaScript to reorder those answers according to the array order

It would require a fair amount of coding and the code would depend on question type, number and placement of "fixed" answers, etc.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 11 years 1 month ago by tpartner.
The topic has been locked.
  • jimstarks
  • jimstarks's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 1 month ago #101837 by jimstarks
I appreciate the feedback.

I was hoping there was a less complicated solution that I was just missing. I like the idea of generating an order array and applying it across questions that use the same list/subquestions, etc.

Thanks...JIM
The topic has been locked.
More
11 years 1 month ago #101971 by id_wahyu
Hi Tony, since we are talking about Randomizing.
Can we have a ROTATE order, instead of totally random? ...

E.g
The order:
att2, att3, att4, att1
att4, att4, att1, att2

Thanks in advance.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 1 month ago #101983 by tpartner
You could use the {SUBMITID} variable (which is available after the first page submission) and the JavaScript modulus operator to rotate through an array of answer codes.

So, placing something like this in the source of a short-text question will load the rotated array into that question and hide it.
Code:
<script type="text/javascript" charset="utf-8">  
 
  $(document).ready(function() { 
 
    var qID = {QID};
    var submitID = {SUBMITID};
 
    // Array of answer codes
    var codeArray = ['SQ001', 'SQ002', 'SQ003', 'SQ004'];
 
    // Find the modulus of the submit ID by the array length
    var submitModulus = submitID % codeArray.length;
 
    // Rotate through the array depending on the modulus
    for (var i=0; i<submitModulus; i++) {
      codeArray.push(codeArray.shift())
    }
 
     // Hide the hidden question
    $('#question'+qID+' input.text').hide();
 
     // Load the hidden question
    $('#question'+qID+' input.text').val(codeArray);
  });
</script>

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: id_wahyu
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose