Anchor subquestions on top of random order array

More
1 month 3 weeks ago #158237 by Matadeleo
Matadeleo created the topic: Anchor subquestions on top of random order array
Hi guys,

I'm trying to anchor a specific sub-question on top of an array that has been randomised.

I've attached an example survey that has an example array and the option that should be "fixed" to the top has a note.

File Attachment:

File Name: anchoring.lss
File Size:17 KB


If it helps, here is some similar code used to fix answer options to bottom of a list:
<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;
 
		// Identify this question
		var qID = {QID}; 
 
		// Find the number of answers
		var ansCount = $('#question'+qID+' li.answer-item').length;
 
		// 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$="X'+qID+(ansCount-fixedIndex)+'"]');
			var answerItem = $(answer).closest('li');
			var answersList = $(answer).closest('ul');
			$(answersList).append(answerItem);
			fixedIndex--;
		}		
	});
</script>
Attachments:

Please Log in to join the conversation.

More
1 month 3 weeks ago - 1 month 3 weeks ago #158246 by tpartner
tpartner replied the topic: Anchor subquestions on top of random order array
This should do the trick:

<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:complete',function() {
 
		// Define the subquestion code to be fixed at the top of the array
		var fixedCode = '1';
 
		// Move that row to the top
		$('#question{QID} table.subquestion-list tbody:eq(0)').prepend($('tr[id$="X{QID}'+fixedCode+'"]'));
 
		// Fix up the row background colours
		$('#question{QID} tr').each(function(i){
			$(this).removeClass('array1, array2');
			if(i % 2 == 0) {
				$(this).addClass('array1');
			}
			else {
				$(this).addClass('array2');
			}
		});
	});
</script>

Here's your survey back with that script included in the question text.

File Attachment:

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

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last Edit: 1 month 3 weeks ago by tpartner.
The following user(s) said Thank You: Matadeleo

Please Log in to join the conversation.

More
1 month 2 weeks ago #158335 by Matadeleo
Matadeleo replied the topic: Anchor subquestions on top of random order array
Works perfectly, thanks tpartner

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now