Randomise subquestions of an array

More
6 years 1 month ago #82490 by CROOZEmaster
CROOZEmaster created the topic: Randomise subquestions of an array
Hello,

I have searched the documentation and the forum, but could not find the answer to this question: how can I randomise the subquestions of an array quetion, so that each participant to the survey gets the subquestions in another order?

Thanks for your help.

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

More
6 years 1 month ago #82493 by Mazi
Mazi replied the topic: Randomise subquestions of an array
You can find that option at the advanced question settings: docs.limesurvey.org/Advanced+question+se...eSurvey#random_order


Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

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

More
6 years 1 month ago #82535 by CROOZEmaster
CROOZEmaster replied the topic: Randomise subquestions of an array
Thanks for your reply.

I tried that, but it only randomizes the ANSWERS, not the subquestions. I want the Answers to allways stay in the same order, but the Subquestions randomized.
I could interchange the Answers with the Subquestions, but I have an array with abt. 25 Subquestions and 6 Answers. Putting these 25 questions on the Y axis makes it impossible to read them.
Or am I missing something ?

Thanks for your help.

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

More
6 years 1 month ago #82551 by CROOZEmaster
CROOZEmaster replied the topic: Randomise subquestions of an array
I found a solution for my problem as follows

I inserted the following code into the question field of the arrow question:

<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() { 
 
		// Find the survey and group IDs
		if($( 'input#fieldnames' ).length != 0) {
			var fieldNames = $( 'input#fieldnames' ).attr('value');
			var tmp = fieldNames.split('X');
			var sID = tmp[0];
			var gID = tmp[1];
		}
 
		////// HANDLE THE ARRAY QUESTIONS //////
 
		// Build an array of the array sub-question codes
		var subquestions = new Array();
		var qID = $('.array-flexible-row:eq(0)').attr('id').split('question')[1];
		$('.array-flexible-row:eq(0) table.question tbody').each(function(i){
			var ansCode = $(this).attr('id').split('X'+qID+'')[1];
			subquestions.push(ansCode);
		});
 
		// Shuffle the sub-question codes
		shuffle(subquestions);
 
		// Loop through all array questions and randomize them in the same order
		$('.array-flexible-row').each(function(i){
			var qID2 = $(this).attr('id').split('question')[1];
			$(subquestions).each(function(i){
				$('#question'+qID2+' table.question').prepend($('#javatbd'+sID+'X'+gID+'X'+qID2+this));
			});
 
			// Fix up the row background colours
			var rowIndex = 0;
			$('#question'+qID2+' table.question tbody tr').each(function(i, el){
				rowIndex ++;
 
				$(el).removeClass('array1, array2');
 
				if(rowIndex % 2 == 0) {
					$(el).addClass('array1');
				}
				else {
					$(el).addClass('array2');
				}
			});
		});
 
 
 
	});
 
</script>

This works perfectly. I had to enable Javascript for the survey and set "Random Order" for the array question itself to "Yes"

I hope this helps others who have the same problem.

Frank

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

More
6 years 1 month ago #82586 by Mazi
Mazi replied the topic: Randomise subquestions of an array
Usually the "random order" should do the trick and work on subquestions.

Which Limesurvey version did you use?

Which question type did you test?


Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

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

More
6 years 1 month ago #82587 by CROOZEmaster
CROOZEmaster replied the topic: Randomise subquestions of an array
The random order shuffles the Answers, not the questions. In my case anyway. I have Versie 1.92+ Build 120613
That was the latest AFAIK. Just found out that there is a newer version released today.

I tested the random feature on a (regular) matrix question. And solved the problem there with the script above.

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

More
6 years 1 month ago #82612 by Mazi
Mazi replied the topic: Randomise subquestions of an array
Ahh, I think this just was a misunderstanding. Maybe you are looking for something like docs.limesurvey.org/Advanced+question+se...eSurvey#random_group


Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

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

More
6 years 1 month ago #82896 by Kasha
Kasha replied the topic: Aw: Randomise subquestions of an array
Hey there!

I am would like to randomize the subquestions (columns) in a text-array question. I tried the code displayed above but it didnt work :(. If I change the option "randomized answers", the lines change but not the columns. What exactly do I need to do to get this script to work? (Have another script which works, so javascript is on). Unfortunately due to the specific design I cannot switch rows with columns.

Thanks in advance! :)

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

More
6 years 1 month ago - 6 years 1 month ago #82995 by tpartner
tpartner replied the topic: Aw: Randomise subquestions of an array
Try this (replace "QQ" with the array ID):
$(document).ready(function() {
 
		randomizeColumns(QQ);
 
		function randomizeColumns(qID) {
 
			var colsArr = new Array();
 
			// Assign some classes and create an array of sub-question columns
			$('#question'+qID+' table.question thead th').each(function(i){
				$(this).addClass('answerCol-'+(i+1)+'');
				colsArr.push(i+1);
			});
			$('#question'+qID+' table.question tbody tr').each(function(i){
				$('td', this).each(function(i){
					$(this).addClass('answerCol-'+(i+1)+'');
				});
			});
 
			// Shuffle the columns array
			function shuffle(o){
				for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
				return o;
			}			
			shuffle(colsArr);
 
			// Insert the table cells in the shuffled order
			$(colsArr).each(function(i){
				var val = this;
				$('#question'+qID+' table.question thead th.answerCol-'+val+'').appendTo($('#question'+qID+' table.question thead tr'));
				$('#question'+qID+' table.question tbody tr').each(function(i){
					$('td.answerCol-'+val+'', this).appendTo($(this));
				});
			});
		}
	});

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

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

More
6 years 1 month ago - 6 years 1 month ago #83075 by Kasha
Kasha replied the topic: Aw: Randomise subquestions of an array
Thank you very much! :)
Last Edit: 6 years 1 month ago by Kasha.

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!