Randomise Array question

More
3 years 8 months ago #101780 by paulfiner
paulfiner created the topic: Randomise Array question
Apologise for the double-post, my original was submitted to the wrong section.

I have an array type question with 13 sub-questions (rows). Is it possible to randomise the order of the sub-questions but leave the last one in place. My last row is 'Other' and I don't want this to be randomised.

Using V1.92

Please Log in to join the conversation.

More
3 years 8 months ago #101792 by tpartner
tpartner replied the topic: Randomise Array question
Assuming the question is just a normal array...

1) Assign the "Other" sub-question code 99

2) Set the question "Random answer order" to "Yes"

3) Add this script to the question source:
<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() { 
 
		// Assign some vars
		var qID = {QID};		
		var fixedID = '99';
 
		// Move the "Other" row to the end
		$('#question'+qID+' table.question').append($('#question'+qID+' tbody[id$="X'+qID+fixedID+'"]'));
    });
</script>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
3 years 8 months ago #101795 by paulfiner
paulfiner replied the topic: Randomise Array question
Hi Tony

Thanks for this, I'll give it a go shortly.

Cheers

Paul

Please Log in to join the conversation.

More
3 years 8 months ago #101804 by paulfiner
paulfiner replied the topic: Randomise Array question
Hi Tony

This works but the alternate row highlighting gets messed up. Is that easy to fix?

Cheers

Paul

Please Log in to join the conversation.

More
3 years 8 months ago - 3 years 8 months ago #101808 by tpartner
tpartner replied the topic: Randomise Array question
Sure...

<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() { 
 
		// Identify things
		var qID = {QID};		
		var fixedID = '99';
 
		// Move the "Other" row to the end
		$('#question'+qID+' table.question').append($('#question'+qID+' tbody[id$="X'+qID+fixedID+'"]'));
 
		// Fix up the array row background colours
		$('#question'+qID+' table.question tbody tr').removeClass('array1 array2');
		$('#question'+qID+' table.question tbody tr').each(function(i){
			$(this).addClass('array'+(2-(i%2)));
		});
    });
</script>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 3 years 8 months ago by tpartner.

Please Log in to join the conversation.

More
3 years 8 months ago #101809 by paulfiner
paulfiner replied the topic: Randomise Array question
Fantastic! Much appreciated as ever!

Cheers

Paul

Please Log in to join the conversation.

Did you already participate in our customer survey?

Don't miss your chance for great prices.

Please click here to participate:

Start now

Start now!

Just create your account and start using Limesurvey today.

Register now