Randomizing a fixed pattern for attribute display

More
3 years 6 months ago #101820 by jimstarks
jimstarks created the topic: Randomizing a fixed pattern for attribute display
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

Please Log in to join the conversation.

More
3 years 6 months ago - 3 years 6 months ago #101832 by tpartner
tpartner replied the topic: Randomizing a fixed pattern for attribute display
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: 3 years 6 months ago by tpartner.

Please Log in to join the conversation.

More
3 years 6 months ago #101837 by jimstarks
jimstarks replied the topic: Randomizing a fixed pattern for attribute display
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

Please Log in to join the conversation.

More
3 years 5 months ago #101971 by id_wahyu
id_wahyu replied the topic: Randomizing a fixed pattern for attribute display
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.

Please Log in to join the conversation.

More
3 years 5 months ago #101983 by tpartner
tpartner replied the topic: Randomizing a fixed pattern for attribute display
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.
The following user(s) said Thank You: id_wahyu

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now