- Posts: 10223
- Thank you received: 3640
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ //Identify this question var thisQuestion = $('#question{QID}'); var thisAnswerList = $('table.subquestion-list tbody:eq(0)', thisQuestion); // Retrieve the answer codes from the "randomOrder" question var answerCodes = '{randomOrder}'.split(','); // Loop through the answer codes $.each(answerCodes, function(i, val) { // Move the array row $(thisAnswerList).append($('tr.answers-list[id$="X{QID}'+val+'"]', thisQuestion)); }); }); </script>
Is it possible to take this one step further and have the array question in the same group as the radio list question?
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify the questions var thisQID = {QID}; var thisQuestion = $('#question'+thisQID); var prevQuestion = $(thisQuestion).prevAll('.multiple-opt:eq(0)'); var prevQID = $(prevQuestion).attr('id').replace(/question/, ''); // Loop through the previous question sub-questions $('.answer-item', prevQuestion).each(function(i) { // Move the sub-questions var thisCode = $(this).attr('id').split('X'+prevQID)[1]; $('.answers-list ul:eq(0)', thisQuestion).append($('.answer-item[id$="X'+thisQID+thisCode+'"]', thisQuestion)); }); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify the questions var thisQID = {QID}; var thisQuestion = $('#question'+thisQID); var prevQuestion = $(thisQuestion).prevAll('.list-radio:eq(0)'); var prevQID = $(prevQuestion).attr('id').replace(/question/, ''); // Loop through the previous question answers $('.answer-item', prevQuestion).each(function(i) { // Move the sub-questions var thisCode = $(this).attr('id').split('X'+prevQID)[1]; $('.answers-list ul:eq(0)', thisQuestion).append($('.answer-item[id$="X'+thisQID+thisCode+'"]', thisQuestion)); }); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify the questions var thisQID = {QID}; var thisQuestion = $('#question'+thisQID); var prevQuestion = $(thisQuestion).prevAll('.list-radio:eq(0)'); var prevQID = $(prevQuestion).attr('id').replace(/question/, ''); // Loop through the previous question answers $('.answer-item', prevQuestion).each(function(i) { // Move the sub-questions var thisCode = $(this).attr('id').split('X'+prevQID)[1]; $('table.subquestion-list tbody:eq(0)', thisQuestion).append($('.answers-list[id$="X'+thisQID+thisCode+'"]', thisQuestion)); }); }); </script>
tpartner wrote:
4) Add this script to the source of following list-radio questions:
Code:<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ //Identify this question var thisQuestion = $('#question{QID}'); var thisAnswerList = $('li.answer-item:eq(0)', thisQuestion).parent(); // Retrieve the answer codes from the "randomOrder" question var answerCodes = '{randomOrder}'.split(','); // Loop through the answer codes $.each(answerCodes, function(i, val) { // Move the answer item $(thisAnswerList).append($('li.answer-item[id$="X{QID}'+val+'"]', thisQuestion)); }); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ //Identify this question var thisQuestion = $('#question{QID}'); var thisAnswerList = $('.answer-item:eq(0)', thisQuestion).parent(); // Determine the number of items in the first column var rowCount = $('.multiple-choice-container > div:eq(0) .question-item', thisQuestion).length; // Retrieve the answer codes from the "randomOrder" question var answerCodes = '{randomOrder}'.split(','); // Loop through the answer codes var row = 0; var column = 0; $.each(answerCodes, function(i, val) { // Move the answer item $('.multiple-choice-container > div:eq('+column+') > div', thisQuestion).append($('.answer-item[id$="X{QID}'+val+'"]', thisQuestion).parent()); if(row < (rowCount-1)) { row++; } else { // Increment the column row = 0; column++; } }); }); </script>