- Posts: 193
- Thank you received: 69
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
- elissa
- Topic Author
- Offline
- LimeSurvey Community Team
Less
More
2 years 10 months ago - 2 years 10 months ago #217083
by elissa
Elzbieta Lesinska
LS voluntary Polish translator and supervisor
Question answers order the same as randomized groups was created 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.
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: 2 years 10 months ago by elissa. Reason: Attachment missing
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
2 years 10 months ago #217109
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Question answers order the same as randomized groups
Add an equation question to record the group positions using Qcode.gseq (we'll call this question "groupOrder").
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.
Sample survey attached:
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:
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.
- elissa
- Topic Author
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 193
- Thank you received: 69
2 years 10 months ago #217111
by elissa
Elzbieta Lesinska
LS voluntary Polish translator and supervisor
Replied by elissa on topic Question answers order the same as randomized groups
Thank you very much, Tony. It's great.
Elzbieta Lesinska
LS voluntary Polish translator and supervisor
The topic has been locked.