- Posts: 8
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
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>
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ //Identify the questions var thisQuestion = $('#question{QID}'); var hiddenQuestion = $(thisQuestion).nextAll('.text-short:eq(0)'); // Create an array of answer codes var answerCodes = []; $('.answer-item', thisQuestion).each(function(i) { answerCodes.push($(this).attr('id').split('X{QID}')[1]); }); // Load the hidden question $('input:text', hiddenQuestion).val(answerCodes); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ //Identify this question var thisQuestion = $('#question{QID}'); // Determine the number of items in the first column var rowCount = $('.answers-list.multiple-list > ul:eq(0) .question-item', thisQuestion).length; // Retrieve the answer codes from the "randomOrder" question var answerCodes = '{randomOrder}'.split(','); console.log(answerCodes); // Loop through the answer codes var row = 0; var column = 0; $.each(answerCodes, function(i, val) { // Move the answer item $('.answers-list.multiple-list > ul:eq('+column+')', thisQuestion).append($('.answer-item[id$="X{QID}'+val+'"]', thisQuestion)); if(row < (rowCount-1)) { row++; } else { // Increment the column row = 0; column++; } }); }); </script>