- Posts: 4
- Thank you received: 0
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
- kwalker
- Offline
- New Member
Less
More
7 years 4 months ago #143391
by kwalker
Replied by kwalker on topic Multiple Choice Question Type - Moving the Other subquestion
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>
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.
- midRange
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
7 years 4 months ago #143786
by midRange
Replied by midRange on topic Multiple Choice Question Type - Moving the Other subquestion
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.
- midRange
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
7 years 4 months ago #143787
by midRange
Replied by midRange on topic Multiple Choice Question Type - Moving the Other subquestion
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>
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.
- krosser
- Offline
- Elite Member
Less
More
- Posts: 222
- Thank you received: 10
5 years 4 months ago #176862
by krosser
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.
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Replied by krosser on topic Multiple Choice Question Type - Moving the Other subquestion
tpartner wrote:
Did I hear someone call my name?I asked Dr. Minke about this and he suggested I post on the forum to see if anyone can help adjust the script.
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:
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10612
- Thank you received: 3691
5 years 4 months ago #176948
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 Multiple Choice Question Type - Moving the Other subquestion
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.
- krosser
- Offline
- Elite Member
Less
More
- Posts: 222
- Thank you received: 10
5 years 4 months ago #177015
by krosser
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.
Replied by krosser on topic Multiple Choice Question Type - Moving the Other subquestion
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10612
- Thank you received: 3691
5 years 4 months ago #177022
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 Multiple Choice Question Type - Moving the Other subquestion
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.