Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Randomization "between respondents", but not within a questionnaire...

Re: Randomization "between respondents", but not within a questionnaire... 2 years 5 months ago #75153

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6252
  • Thank you received: 799
  • Karma: 239
I have allways difficulty to attach a file.

But here, we need lss file, not queXML . Maybe it work with lss ..
The administrator has disabled public write access.

Re: Randomization "between respondents", but not within a questionnaire... 2 years 5 months ago #75170

OK. Here is the lss file then (hopefully!).

File Attachment:

File Name: limesurvey_survey_36525.lss
File Size: 193 KB
The administrator has disabled public write access.

Re: Randomization "between respondents", but not within a questionnaire... 2 years 5 months ago #75171

YAY! ;)
The administrator has disabled public write access.

Re: Randomization "between respondents", but not within a questionnaire... 2 years 5 months ago #75174

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4117
  • Thank you received: 760
  • Karma: 346
Okay, I see that in the third group you have several array questions and several multiple-options questions. I assume you want all of the arrays randomized in the same order and all of the multiple-options randomized in the same order.

1) Set up your survey to use JavaScript.

2)Add the following script to the source of one of the questions.

The script sorts all of the array questions into the same random order and then does the same thing for all of the multiple-options questions.
<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');
				}
			});
		});
 
		////// HANDLE THE MULTIPLE-OPTIONS QUESTIONS //////
 
		// Build an array of the multiple-options sub-question codes
		var subquestions2 = new Array();
		var qID3 = $('.multiple-opt-comments:eq(0)').attr('id').split('question')[1];
		$('.multiple-opt-comments:eq(0) li[id^="javatbd"]').each(function(i){
			var ansCode3 = $(this).attr('id').split('X'+qID3+'')[1];
			subquestions2.push(ansCode3);
		});
 
		// Shuffle the sub-question codes
		shuffle(subquestions2);
 
		// Loop through all multiple-options questions and randomize them in the same order
		$('.multiple-opt-comments').each(function(i){
			var qID4 = $(this).attr('id').split('question')[1];
			$(subquestions2).each(function(i){
				$('#question'+qID4+' li[id^="javatbd"]:eq(0)').parent().prepend($('#javatbd'+sID+'X'+gID+'X'+qID4+this));
			});
		});
 
		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;
		}			
 
	});
 
</script>

Here is your sample survey back with the script in the source of the first question of group 3.

File Attachment:

File Name: limesurvey_survey_36525_TP.lss
File Size: 199 KB
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.

Re: Randomization "between respondents", but not within a questionnaire... 2 years 5 months ago #75386

Thanks so much tpartner!

But I still have questions:
1- How do I "set up my survey to use JavaScript"?
2- What should I do for the other questions? Would copy-paste work??
3- What do I do with that file?

And just to be sure, this script will enable me to have the same orders for array/sub-questions in one given questionnaire, but different order for the next respondent, right?

I told you, my IT skills are very limited!

Thanks again!
Marie
The administrator has disabled public write access.

Re: Randomization "between respondents", but not within a questionnaire... 2 years 5 months ago #75392

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4117
  • Thank you received: 760
  • Karma: 346
How do I "set up my survey to use JavaScript"?
Follow the instructions in the link - docs.limesurvey.org/tiki-index.php?page=..._etc._in_LimeSurvey_
What should I do for the other questions? Would copy-paste work??
You only need to add the script to one question in the group.
What do I do with that file?
If you mean the attached survey, it is an example of the script working for you to import/copy/modify for your use.
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.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.136 seconds
Donation Image