Check out the LimeSurvey source code on GitHub!

Randomise Array question

More
3 years 1 month ago #101780 by paulfiner
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 1 month ago #101792 by tpartner
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 1 month ago #101795 by paulfiner
Hi Tony

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

Cheers

Paul

Please Log in to join the conversation.

More
3 years 1 month ago #101804 by paulfiner
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 1 month ago - 3 years 1 month ago #101808 by tpartner
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 1 month ago by tpartner.

Please Log in to join the conversation.

More
3 years 1 month ago #101809 by paulfiner
Fantastic! Much appreciated as ever!

Cheers

Paul

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form