Welcome, Guest
Username: Password: Remember me

TOPIC: Randomise Array question

Randomise Array question 11 months 2 days ago #101780

  • paulfiner
  • paulfiner's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 92
  • Thank you received: 1
  • Karma: 1
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
The administrator has disabled public write access.

Randomise Array question 11 months 2 days ago #101792

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4272
  • Thank you received: 806
  • Karma: 369
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Randomise Array question 11 months 2 days ago #101795

  • paulfiner
  • paulfiner's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 92
  • Thank you received: 1
  • Karma: 1
Hi Tony

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

Cheers

Paul
The administrator has disabled public write access.

Randomise Array question 11 months 2 days ago #101804

  • paulfiner
  • paulfiner's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 92
  • Thank you received: 1
  • Karma: 1
Hi Tony

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

Cheers

Paul
The administrator has disabled public write access.

Randomise Array question 11 months 2 days ago #101808

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4272
  • Thank you received: 806
  • Karma: 369
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.

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

Randomise Array question 11 months 2 days ago #101809

  • paulfiner
  • paulfiner's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 92
  • Thank you received: 1
  • Karma: 1
Fantastic! Much appreciated as ever!

Cheers

Paul
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.117 seconds
Donation Image