- Posts: 61
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
How to place a certain option at the end of a list with randomized answers
- vzyldd
- Topic Author
- Offline
- Senior Member
Less
More
6 years 1 month ago #165478
by vzyldd
How to place a certain option at the end of a list with randomized answers was created by vzyldd
Question type: Array
Limesurvey version: Version 3.5.1+180312
I need to keep the last option in the subquestion list (total of 6 subquestions) last when I randomize option 1 to 5. I found the following script and used it in the question but not working in this version. Any suggestions?
<script type='text/javascript'>
/* Place option 6 at the end of the randomized list */
$(document).ready(function() {
var move_element="6";
/* Please do NOT change the lines below */
var move_element="javatbd{SGQ}"+move_element;
$("#"+move_element).insertAfter("#question{QID} .answers-list .answer-item:last-child");
});
</script>
Limesurvey version: Version 3.5.1+180312
I need to keep the last option in the subquestion list (total of 6 subquestions) last when I randomize option 1 to 5. I found the following script and used it in the question but not working in this version. Any suggestions?
<script type='text/javascript'>
/* Place option 6 at the end of the randomized list */
$(document).ready(function() {
var move_element="6";
/* Please do NOT change the lines below */
var move_element="javatbd{SGQ}"+move_element;
$("#"+move_element).insertAfter("#question{QID} .answers-list .answer-item:last-child");
});
</script>
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10115
- Thank you received: 3597
6 years 1 month ago - 6 years 1 month ago #165485
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 How to place a certain option at the end of a list with randomized answers
Add something like this to the question source:
Sample survey attached:
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:complete',function() { // Define the subquestion code to be fixed at the bottom of the array var fixedCode = 'SQ004'; // Move that row to the bottom $('#question{QID} table.subquestion-list tbody:eq(0)').append($('tr[id$="X{QID}'+fixedCode+'"]')); // Fix up the row background colours $('#question{QID} tr.answers-list').each(function(i){ $(this).removeClass('ls-even, ls-odd'); if(i % 2 == 0) { $(this).addClass('ls-even'); } else { $(this).addClass('ls-odd'); } }); }); </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last edit: 6 years 1 month ago by tpartner.
The topic has been locked.
- vzyldd
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 61
- Thank you received: 0
6 years 1 month ago #165491
by vzyldd
Replied by vzyldd on topic How to place a certain option at the end of a list with randomized answers
Thank you Tony. Just what I need.
The topic has been locked.
- SabrinaCasanova
- Offline
- New Member
Less
More
- Posts: 15
- Thank you received: 0
4 years 9 months ago #186536
by SabrinaCasanova
Replied by SabrinaCasanova on topic How to place a certain option at the end of a list with randomized answers
Hi,
I tried this script on radio list question but not working in limesurvey 2.57. Please advise.
I want the two option with code 98 and 99 at the end and after the "other" option.
In attachment the survey.
below the script :
<script type='text/javascript'>
/* Place option 98 at the end of the randomized list */
$(document).ready(function() {
var move_element="98";
/* Please do NOT change the lines below */
var move_element="javatbd{SGQ}"+move_element;
$("#"+move_element).insertAfter("#question{QID} .answers-list .answer-item:last-child");
});
</script>
<script type='text/javascript'>
/* Place option 99 at the end of the randomized list */
$(document).ready(function() {
var move_element="99";
/* Please do NOT change the lines below */
var move_element="javatbd{SGQ}"+move_element;
$("#"+move_element).insertAfter("#question{QID} .answers-list .answer-item:last-child");
});
</script>
Thanks
I tried this script on radio list question but not working in limesurvey 2.57. Please advise.
I want the two option with code 98 and 99 at the end and after the "other" option.
In attachment the survey.
below the script :
<script type='text/javascript'>
/* Place option 98 at the end of the randomized list */
$(document).ready(function() {
var move_element="98";
/* Please do NOT change the lines below */
var move_element="javatbd{SGQ}"+move_element;
$("#"+move_element).insertAfter("#question{QID} .answers-list .answer-item:last-child");
});
</script>
<script type='text/javascript'>
/* Place option 99 at the end of the randomized list */
$(document).ready(function() {
var move_element="99";
/* Please do NOT change the lines below */
var move_element="javatbd{SGQ}"+move_element;
$("#"+move_element).insertAfter("#question{QID} .answers-list .answer-item:last-child");
});
</script>
Thanks
Attachments:
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12996
- Thank you received: 3999
4 years 9 months ago - 4 years 9 months ago #186538
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic How to place a certain option at the end of a list with randomized answers
Hi, Sabrina
Here you find the scripts for all version (2.06, 2.50-2.73, 3.x)
manual.limesurvey.org/Workarounds:_Manip...tions_.28Enhanced.29
Use this one for LS version 2.50-2.73
And an example
Best regards
Joffm
Here you find the scripts for all version (2.06, 2.50-2.73, 3.x)
manual.limesurvey.org/Workarounds:_Manip...tions_.28Enhanced.29
Use this one for LS version 2.50-2.73
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; // Set this to "true" if you want "Other" to be fixed in the last position var otherFixed = false; // Identify this question var qID = {QID}; // Find the number of answers var ansCount = $('#question'+qID+' .answer-item').length; if($('#question'+qID+' input[type="text"]').length > 0) { ansCount = ansCount -1 } // Place the last n answers created at the end of the list var fixedIndex = fixedAnswers - 1; for (var i=0; i<fixedAnswers; i++) { var answer = $('input[id^="answer"][id$="X'+qID+'s'+(ansCount-fixedIndex)+'"]'); var answerItem = $(answer).closest('.answer-item'); var answersList = $(answer).closest('.answers-list'); if($('#question'+qID).hasClass('multiple-opt')) { answer = $('input[id^="answer"][id$="X'+qID+(ansCount-fixedIndex)+'"]'); answerItem = $(answer).closest('.answer-item').parent(); answersList = $(answer).closest('.subquestion-list'); } $(answersList).append(answerItem); fixedIndex--; } // Handle "Other" if(otherFixed == true && $('#question'+qID+' input[type="text"]').length > 0) { var otherAnswer = $('#question'+qID+' input[type="text"]'); var otherAnswerItem = $(otherAnswer ).closest('.answer-item'); var otherAnswersList = $(otherAnswer ).closest('.answers-list'); if($('#question'+qID).hasClass('multiple-opt')) { otherAnswerItem = $(otherAnswer ).closest('.answer-item').parent(); otherAnswersList = $(otherAnswer ).closest('.subquestion-list'); } $(otherAnswersList).append(otherAnswerItem); } }); </script>
And an example
Best regards
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 4 years 9 months ago by Joffm.
The following user(s) said Thank You: SabrinaCasanova
The topic has been locked.
- SabrinaCasanova
- Offline
- New Member
Less
More
- Posts: 15
- Thank you received: 0
4 years 9 months ago #186541
by SabrinaCasanova
Replied by SabrinaCasanova on topic How to place a certain option at the end of a list with randomized answers
Thanks a lot :kiss:
The topic has been locked.
- SabrinaCasanova
- Offline
- New Member
Less
More
- Posts: 15
- Thank you received: 0
4 years 9 months ago #186816
by SabrinaCasanova
Replied by SabrinaCasanova on topic How to place a certain option at the end of a list with randomized answers
Working on Q2 (multiple choice) but not on Q01 and Q1 (single choice) for limesurvey 2.57.1
Please advice
Please advice
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12996
- Thank you received: 3999
4 years 9 months ago #186819
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic How to place a certain option at the end of a list with randomized answers
Hi, Sabrina,
I do not see any issue.
I only can test in Version 2.73.1+171220
As you might have seem in the manual
manual.limesurvey.org/Workarounds:_Manip...tions_.28Enhanced.29
and what I did not:
It is only tested in 2.70, not in earlier versions of this branch.
To check this, please send your survey (only the respective questions) as *.lss
So, we'll see if it's a version problem (meaning you have to update) or something else.
As your version was released in december 2016 you really should consider this.
And if you would like to stay to your used branch (2.50-2.73) you find the latest version here.
www.limesurvey.org/downloads/category/24-archived-releases
Best regards
Joffm
I do not see any issue.
I only can test in Version 2.73.1+171220
As you might have seem in the manual
manual.limesurvey.org/Workarounds:_Manip...tions_.28Enhanced.29
and what I did not:
It is only tested in 2.70, not in earlier versions of this branch.
To check this, please send your survey (only the respective questions) as *.lss
So, we'll see if it's a version problem (meaning you have to update) or something else.
As your version was released in december 2016 you really should consider this.
And if you would like to stay to your used branch (2.50-2.73) you find the latest version here.
www.limesurvey.org/downloads/category/24-archived-releases
Best regards
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10115
- Thank you received: 3597
4 years 9 months ago - 4 years 8 months ago #186825
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 How to place a certain option at the end of a list with randomized answers
@Joffm, actually that may be broken. If otherFixed = true, then that option should appear at the very end of the list, not second last as in your screenshot.
I'm not in s position to test in the next couple of days but will look into it as soon as possible.
I'm not in s position to test in the next couple of days but will look into it as soon as possible.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 8 months ago by tpartner.
The topic has been locked.
- SabrinaCasanova
- Offline
- New Member
Less
More
- Posts: 15
- Thank you received: 0
4 years 8 months ago #187278
by SabrinaCasanova
Replied by SabrinaCasanova on topic How to place a certain option at the end of a list with randomized answers
Hi,
I tried with Version 3.17.8+190722 and also not working, please advice.
Thanks
I tried with Version 3.17.8+190722 and also not working, please advice.
Thanks
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12996
- Thank you received: 3999
4 years 8 months ago #187281
by Joffm
I showed that it worked in 2.60/2.73 (except of Tony's remark)
And here I show it in 3.X
1. "Option 4", "Option 5" and "Other" fixed
2. "Option 4", "Option 5" fixed, but "Other" not fixed
So I advice to
send the respective question(s) as *.lss.
Joffm
How can we try to help without knowing what you are doing?
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic How to place a certain option at the end of a list with randomized answers
What is not working???and also not working, please advice.
I showed that it worked in 2.60/2.73 (except of Tony's remark)
And here I show it in 3.X
1. "Option 4", "Option 5" and "Other" fixed
2. "Option 4", "Option 5" fixed, but "Other" not fixed
So I advice to
send the respective question(s) as *.lss.
Joffm
How can we try to help without knowing what you are doing?
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: DenisChenu, tpartner
The topic has been locked.
- SabrinaCasanova
- Offline
- New Member
Less
More
- Posts: 15
- Thank you received: 0
4 years 8 months ago #187285
by SabrinaCasanova
Replied by SabrinaCasanova on topic How to place a certain option at the end of a list with randomized answers
Attachments:
The topic has been locked.