Welcome, Guest
Username: Password: Remember me

TOPIC: Randomizing a fixed pattern for attribute display

Randomizing a fixed pattern for attribute display 1 year 1 week ago #101820

  • jimstarks
  • jimstarks's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 8
  • Karma: 0
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 administrator has disabled public write access.

Randomizing a fixed pattern for attribute display 1 year 1 week ago #101832

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4372
  • Thank you received: 830
  • Karma: 381
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 1 year 1 week ago by tpartner.
The administrator has disabled public write access.

Randomizing a fixed pattern for attribute display 1 year 1 week ago #101837

  • jimstarks
  • jimstarks's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 8
  • Karma: 0
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 administrator has disabled public write access.

Randomizing a fixed pattern for attribute display 1 year 2 days ago #101971

  • id_wahyu
  • id_wahyu's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 30
  • Karma: 0
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 administrator has disabled public write access.

Randomizing a fixed pattern for attribute display 1 year 2 days ago #101983

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4372
  • Thank you received: 830
  • Karma: 381
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.
<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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: id_wahyu
Moderators: ITEd
Time to create page: 0.111 seconds
Donation Image