Multiple Choice Question Type - Moving the Other subquestion

More
6 months 6 days 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):

<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.
<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.17 hosted on LS servers, not installed locally.

Please Log in or Create an account to join the conversation.

More
6 months 5 days ago #176948 by tpartner
This will work in 3.x:

<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.
Official LimeSurvey Partner - partnersurveys.com
The following user(s) said Thank You: elissa, krosser

Please Log in or Create an account to join the conversation.

More
6 months 4 days ago #177015 by krosser

tpartner wrote: This will work in 3.x:

<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.17 hosted on LS servers, not installed locally.

Please Log in or Create an account to join the conversation.

More
6 months 4 days 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.
Official LimeSurvey Partner - partnersurveys.com

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!