- Posts: 107
- Thank you received: 4
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Anchor subquestions on top of random order array
- Matadeleo
- Topic Author
- Offline
- Premium Member
Less
More
6 years 7 months ago #158237
by Matadeleo
Anchor subquestions on top of random order array was created by Matadeleo
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.
If it helps, here is some similar code used to fix answer options to bottom of a list:
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.
If it helps, here is some similar code used to fix answer options to bottom of a list:
Code:
<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:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
6 years 7 months ago - 6 years 7 months ago #158246
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 Anchor subquestions on top of random order array
This should do the trick:
Here's your survey back with that script included in the question text.
Code:
<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.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last edit: 6 years 7 months ago by tpartner.
The following user(s) said Thank You: Matadeleo
The topic has been locked.
- Matadeleo
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 107
- Thank you received: 4
6 years 7 months ago #158335
by Matadeleo
Replied by Matadeleo on topic Anchor subquestions on top of random order array
Works perfectly, thanks tpartner
The topic has been locked.