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
7 years 6 months ago #143391 by kwalker
Thanks everyone for your help!

If you want to modify the original script from Dr. Minke, I think this should work:

<script type='text/javascript'>
$(document).ready(function() {

var move_element="other";
var place_before="8";

var place_before=("javatbd{SGQ}"+place_before);
var move_element="javatbd{SGQ}"+move_element;
var parent_before=$("#"+place_before).parent();

$("#"+move_element).parent().insertBefore(parent_before);

});
</script>
The topic has been locked.
More
7 years 5 months ago #143786 by midRange
Hello, great solutions here. Very helpful and many thanks. I have a question about a List (Radio) type question and how to move the other button around like the above solutions. I have tried the JS on a List (Radio) type question, but I am unable to move the Other option to where I want. Any suggestions?
The topic has been locked.
More
7 years 5 months ago #143787 by midRange
Disregard my post above. I simply had to modify the JS script to account for the different HTML on the List (Radio) Type page.
Removed .parent() from variables otherRow and replaceRow

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

$(replaceRow).before($(otherRow));
});
</script>
The topic has been locked.
More
5 years 5 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 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.
  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 5 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
5 years 5 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.
  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 5 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.

Lime-years ahead

Online-surveys for every purse and purpose