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
  • vzyldd's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 1 week ago #165478 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>
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 1 week ago - 6 years 1 week ago #165485 by tpartner
Add something like this to the question source:

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:

File Attachment:

File Name: limesurvey...9162.lss
File Size:18 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 years 1 week ago by tpartner.
The topic has been locked.
  • vzyldd
  • vzyldd's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 1 week ago #165491 by vzyldd
Thank you Tony. Just what I need.
The topic has been locked.
More
4 years 8 months ago #186536 by SabrinaCasanova
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
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 8 months ago - 4 years 8 months ago #186538 by Joffm
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
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 &amp;&amp; $('#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

File Attachment:

File Name: limesurvey...2319.lss
File Size:45 KB


Best regards
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 4 years 8 months ago by Joffm.
The following user(s) said Thank You: SabrinaCasanova
The topic has been locked.
More
4 years 8 months ago #186541 by SabrinaCasanova
Thanks a lot :kiss:
The topic has been locked.
More
4 years 8 months ago #186816 by SabrinaCasanova
Working on Q2 (multiple choice) but not on Q01 and Q1 (single choice) for limesurvey 2.57.1

Please advice
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 8 months ago #186819 by Joffm
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

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 8 months ago - 4 years 7 months ago #186825 by tpartner
@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.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 7 months ago by tpartner.
The topic has been locked.
More
4 years 7 months ago #187278 by SabrinaCasanova
Hi,

I tried with Version 3.17.8+190722 and also not working, please advice.

Thanks
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 7 months ago #187281 by Joffm

and also not working, please advice.

What is not working???
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.
More
4 years 7 months ago #187285 by SabrinaCasanova
Hi,

The fixed options at the end not working for me for two version :

Version 2.57



Version 3.17


Thanks
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose