- Posts: 10099
- Thank you received: 3589
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Partially randomized answers (list radio type) in 2.50
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
6 years 4 months ago #160907
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 Partially randomized answers (list radio type) in 2.50
In that version, the IDs have changed slightly - use this script:
Sample survey attached:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // The number of answers to be fixed at the end of the list var fixedAnswers = 2; // Identify this question var qID = {QID}; // Find the number of answers var ansCount = $('#question'+qID+' .answer-item').length; // Place the last n answers created at the end of the list var fixedIndex = fixedAnswers - 1; for (var i=0; i<fixedAnswers; i++) { var answerItem = $('.answer-item[id^="javatbd"][id$="X'+qID+(ansCount-fixedIndex)+'"]'); if($('#question'+qID).hasClass('multiple-opt')) { $(answerItem).closest('.subquestion-list').append($(answerItem).parent()); } else { $(answerItem).closest('.answers-list').append(answerItem); } fixedIndex--; } }); </script>
Sample survey attached:
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: blocka
The topic has been locked.
- blocka
- Offline
- Platinum Member
Less
More
- Posts: 409
- Thank you received: 34
6 years 4 months ago #160908
by blocka
Replied by blocka on topic Partially randomized answers (list radio type) in 2.50
Awesome! Thanks so much, I've confirmed it works
The topic has been locked.
- first
- Offline
- Elite Member
Less
More
- Posts: 227
- Thank you received: 36
6 years 4 months ago #161249
by first
Survey Designer and Programmer
Replied by first on topic Partially randomized answers (list radio type) in 2.50
I am back on forums after a long time . Here is my try:
This will go in template.js
and this will go in question text.
tested with Version 2.72.5 and list-radio and multi-checkbox.
This will go in template.js
Code:
function keepPos(SGQ,posArr){ var qtype = ''; var qid = SGQ.split('X')[2]; var $thisq = $('#question'+qid+''); if($thisq.hasClass('multiple-opt')){ qtype = 'multiple-opt'; }else if($thisq.hasClass('list-radio')){ qtype = 'list-radio'; } for (var i = posArr.length - 1; i >= 0; --i) { var thisPair = posArr[i].split('|'); var $allAnsItems = ''; var $thisAnsItem = ''; if(qtype == 'multiple-opt'){ $thisAnsItem = $('#javatbd'+SGQ+''+thisPair[0]+'').parent(); $allAnsItems = $('.answer-item',$thisq).parent(); }else if(qtype == 'list-radio'){ $thisAnsItem = $('#javatbd'+SGQ+''+thisPair[0]+''); $allAnsItems = $('.answer-item',$thisq); } $allAnsItems.eq(thisPair[1] - 1).after($thisAnsItem); } }
and this will go in question text.
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { keepPos('{SGQ}',['SQ006|6','SQ007|7']) // keepPos('{SGQ}',['code|position','code|position']) }); </script>
tested with Version 2.72.5 and list-radio and multi-checkbox.
Survey Designer and Programmer
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
6 years 4 months ago #161257
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 Partially randomized answers (list radio type) in 2.50
How is this different or better?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.