Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Question answers order the same as randomized groups

More
5 years 3 months ago - 5 years 3 months 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
Last edit: 5 years 3 months ago by elissa. Reason: Attachment missing
The topic has been locked.
More
5 years 3 months ago #217109 by tpartner
Add an equation question to record the group positions using Qcode.gseq (we'll call this question "groupOrder").
 
 
Code:
{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.
 
 
Code:
<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.15 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: elissa
The topic has been locked.
More
5 years 3 months 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.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose