Question answers order the same as randomized groups

More
1 year 2 weeks ago - 1 year 2 weeks ago #217083 by elissa
Hello Colleagues,

I need your help in solving the randomization problem. I have three question groups that are randomized. Next there is a radio question with three answer options that correspond to the groups. I would like the answer options to show in the same order as the preceding groups. For example: if the groups are shown in the order: Group B, Group A, Group C, the order of the answer options in the next radio question should be:
- Group B
- Group A
- Group C
I'm attaching the sample lss file. LS 3.27.2. Thank you.

Elzbieta Lesinska
LS voluntary Polish translator and supervisor
Attachments:
Last edit: 1 year 2 weeks ago by elissa. Reason: Attachment missing
The topic has been locked.
More
1 year 2 weeks ago #217109 by tpartner
Add an equation question to record the group positions using Qcode.gseq (we'll call this question "groupOrder").
 
 
{A1.gseq},{B1.gseq},{C1.gseq}

Add this script to the source of the radio question. It will sort the group positions in an associative array and move the answer items accordingly.
 
 
<script type="text/javascript" data-author="Tony Partner">	
	$(document).on('ready pjax:scriptcomplete',function(){
 
		// Identify this question
		var thisQID = {QID};
		var thisQuestion = $('#question'+thisQID);
 
		var groupOrder = '{groupOrder.question}'.split(',');		
 
		// Build an associative array of group positions
		var answerIndexes = { };
		$('.answer-item', thisQuestion).each(function(i) {
			var thisCode = $(this).attr('id').split('X'+thisQID)[1];
			answerIndexes[groupOrder[i]] = thisCode;
		});
 
		// Move the answer items
		var answersList = $('.answer-item:eq(0)', thisQuestion).parent();
		$.each(answerIndexes, function(i, val) {
			answersList.append($('.answer-item[id$="X'+thisQID+val+'"]'));
		});
	});
</script>

Sample survey attached: 

File Attachment:

File Name: limesurvey...3(1).lss
File Size:22 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: elissa
The topic has been locked.
More
1 year 2 weeks ago #217111 by elissa
Thank you very much, Tony. It's great.

Elzbieta Lesinska
LS voluntary Polish translator and supervisor
The topic has been locked.

Start now!

Just create your account and start using Limesurvey today.

Register now