Welcome to the LimeSurvey Community Forum

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

Multiple Choice Question Type - Moving the Other subquestion

More
6 years 9 months ago #176862 by krosser

tpartner wrote:

I asked Dr. Minke about this and he suggested I post on the forum to see if anyone can help adjust the script.

Did I hear someone call my name? :)

In version 2.54.3, you can use something like this (note, it may not work in future versions if the HTML structure is changed again):

Code:
<script type="text/javascript" charset="utf-8">    
 
  $(document).ready(function(){
 
    // New position of the "Other" row (edit as required)
    var newPosition = 3;  
 
    //// NO EDITING REQUIRED BELOW HERE ////
 
    var thisQuestion = $('#question{QID}');
 
    var otherRow = $('.answer-item[id$="other"]', thisQuestion).parent();
    var replaceRow = $('.answer-item:eq('+(newPosition-1)+')', thisQuestion).parent();
 
    $(replaceRow).before($(otherRow));
  });
</script>



Sample survey attached:

File Attachment:

File Name: limesurvey...9(1).lss
File Size:16.47 KB



This script does not work in LS 3+. Is there an update for it?

I could manage to move the other modifying the code for a List-radio with other.
Code:
<script type='text/javascript' charset='utf-8'>
$(document).ready(function() {
/* Adjust these settings */
 var move_element="other";
 var place_before="SQ003";
/* Please do NOT change the lines below */
var place_before="javatbd{SGQ}"+place_before;
var move_element="javatbd{SGQ}"+move_element;
$("#"+move_element).insertBefore("#"+place_before);
});
</script>

I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
The topic has been locked.
More
6 years 9 months ago #176948 by tpartner
This will work in 3.x:

Code:
<script type="text/javascript" charset="utf-8">    
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // New position of the "Other" row (edit as required)
    var newPosition = 3;  
 
    //// NO EDITING REQUIRED BELOW HERE ////
 
    var thisQuestion = $('#question{QID}');
 
    var otherRow = $('.answer-item[id$="other"]', thisQuestion);
    var replaceRow = $('.answer-item:eq('+(newPosition-1)+')', thisQuestion);
 
    $(replaceRow).before($(otherRow));
  });
</script>

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, krosser
The topic has been locked.
More
6 years 9 months ago #177015 by krosser

tpartner wrote: This will work in 3.x:

Code:
<script type="text/javascript" charset="utf-8">    
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // New position of the "Other" row (edit as required)
    var newPosition = 3;  
 
    //// NO EDITING REQUIRED BELOW HERE ////
 
    var thisQuestion = $('#question{QID}');
 
    var otherRow = $('.answer-item[id$="other"]', thisQuestion);
    var replaceRow = $('.answer-item:eq('+(newPosition-1)+')', thisQuestion);
 
    $(replaceRow).before($(otherRow));
  });
</script>


Thanks Tony, but it only works for multiple-choice without comments.

I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
The topic has been locked.
More
6 years 9 months ago #177022 by tpartner
Yes, that's what you depicted.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose