Split random order

More
4 months 1 week ago #170957 by Andrea01
Andrea01 created the topic: Split random order
Is it possible to split random order for arrays, multiple choice and radio list questions?

For example question code Q1with subquestions

sq001 subquestion1
sq002 subquestion2
sq003 subquestion3

sq004 subquestion4
sq005 subquestion5
sq006 subquestion6

Subquestion1 to 3 should be in random order between themselves and additionally subquestion4 to 6 should be in their own random order.

Thanks in advance and best regards
Andrea

Please Log in or Create an account to join the conversation.

More
4 months 1 week ago #170959 by Joffm
Joffm replied the topic: Split random order
Hi, Andrea,

shortest and easiest way:

split it into two questions.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in or Create an account to join the conversation.

More
4 months 1 week ago #170960 by Andrea01
Andrea01 replied the topic: Split random order
Thank you Joffm, I habe been thinking about this solution, but I thought there might be a more elegant way.

Also, I just discovered, that I put my request in the wrong forum. Can you please move it to forum "Can I do this with LimeSurvey" or should I post again.

Thanks,
Andrea

Please Log in or Create an account to join the conversation.

More
4 months 1 week ago #170961 by Joffm
Joffm replied the topic: Split random order
Hi, Andrea,
I know it's not very elegent.

But at the moment we only have workarounds for half of it: randomized first three, fixed second three.

Don't worry about the section, as long as you post in the correct language.
To be honest: Unfortunately nearly nobody seems to care about the intended content of the first three sections.


Best regards
Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in or Create an account to join the conversation.

More
4 months 1 week ago #170962 by tpartner
tpartner replied the topic: Split random order
You could do it with JavaScript but the script details would depend on the LimeSurvey version used.

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

Please Log in or Create an account to join the conversation.

More
4 months 1 week ago #170971 by Andrea01
Andrea01 replied the topic: Split random order
Hi Tony,

For this survey still using limesurvey2.6.7-lts+171212.

Thanks and best regards
Andrea

Please Log in or Create an account to join the conversation.

More
4 months 1 week ago - 4 months 1 week ago #171003 by tpartner
tpartner replied the topic: Split random order
Place this in template.js:

function shuffleArray(array) {
	for (var i = array.length - 1; i > 0; i--) {
		var j = Math.floor(Math.random() * (i + 1));
		var temp = array[i];
		array[i] = array[j];
		array[j] = temp;
	}
	return array;
}

Place something like this in the source of a multiple-choice question (adjust the sub-question codes as required):

<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {	
 
		// Identify this question
		var qID = {QID};
		var thisQuestion = $('#question'+qID);
 
		// First group of sub-question codes
		var sqCodes1 = ['SQ001', 'SQ002', 'SQ003'];
		// Second group of sub-question codes
		var sqCodes2 = ['SQ004', 'SQ005', 'SQ006'];
 
		// Shuffle the subquestions
		shuffleArray(sqCodes1);
		shuffleArray(sqCodes2);
 
		// Insert the rows in the shuffled order
		$(sqCodes1).each(function(i, val){
			$('.subquestions-list', thisQuestion).append($('.question-item[id$="X'+qID+val+'"]', thisQuestion));
		});
		$(sqCodes2).each(function(i, val){
			$('.subquestions-list', thisQuestion).append($('.question-item[id$="X'+qID+val+'"]', thisQuestion));
		});
	});
</script>

Place something like this in the source of an array question (adjust the sub-question codes as required):

<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {	
 
		// Identify this question
		var qID = {QID};
		var thisQuestion = $('#question'+qID);
 
		// First group of sub-question codes
		var sqCodes1 = ['SQ001', 'SQ002', 'SQ003'];
		// Second group of sub-question codes
		var sqCodes2 = ['SQ004', 'SQ005', 'SQ006'];
 
		// Shuffle the subquestions
		shuffleArray(sqCodes1);
		shuffleArray(sqCodes2);
 
		// Insert the rows in the shuffled order
		$(sqCodes1).each(function(i, val){
			$('table.subquestions-list', thisQuestion).append($('.answers-list[id$="X'+qID+val+'"]', thisQuestion));
		});
		$(sqCodes2).each(function(i, val){
			$('table.subquestions-list', thisQuestion).append($('.answers-list[id$="X'+qID+val+'"]', thisQuestion));
		});
	});
</script>

Place something like this in the source of a list-radio question (adjust the answer codes as required):

<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {	
 
		// Identify this question
		var qID = {QID};
		var thisQuestion = $('#question'+qID);
 
		// First group of answer codes
		var answerCodes1 = ['A1', 'A2', 'A3'];
		// Second group of answer codes
		var answerCodes2 = ['A4', 'A5', 'A6'];
 
		// Shuffle the subquestions
		shuffleArray(answerCodes1);
		shuffleArray(answerCodes2);
 
		// Insert the rows in the shuffled order
		$(answerCodes1).each(function(i, val){
			$('.answers-list', thisQuestion).append($('.answer-item[id$="X'+qID+val+'"]', thisQuestion));
		});
		$(answerCodes2).each(function(i, val){
			$('.answers-list', thisQuestion).append($('.answer-item[id$="X'+qID+val+'"]', thisQuestion));
		});
	});
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...7-10.lss
File Size:25 KB

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last Edit: 4 months 1 week ago by tpartner.
The following user(s) said Thank You: LouisGac

Please Log in or Create an account to join the conversation.

More
4 months 1 week ago #171005 by Andrea01
Andrea01 replied the topic: Split random order
Works perfectly.

Thank you Tony, you are the best.:)

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!