- Posts: 112
- Thank you received: 6
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Identify the questions var thisQuestion = $('#question{QID}'); var genderQuestions = $(thisQuestion).nextAll('.list-radio').slice( 0, 5); var q1Questions = $(thisQuestion).nextAll('.list-radio').slice( 5, 10); var q2Questions = $(thisQuestion).nextAll('.multiple-opt').slice( 0, 5); // Assign some classes $(thisQuestion).addClass('multi-question-array'); $(genderQuestions).addClass('gender-question hidden-question'); $(q1Questions).addClass('q-1-question hidden-question'); $(q2Questions).addClass('q-2-question hidden-question'); // Hide the radio and check-box questions $('.hidden-question').hide(); // Insert the extra columns $('col', thisQuestion).removeAttr('width'); $('colgroup', thisQuestion).append('<col class="even"><col class="odd"><col class="even">'); $('thead tr', thisQuestion).append('<th class="answertext"></th><th class="answertext"></th><th class="answertext"></th>'); $('tr.subquestion-list', thisQuestion).append('<td class="answer-item text-item"></td><td class="answer-item text-item"></td><td class="answer-item text-item"></td>'); $('thead tr> *', this).each(function(i){ $(this).addClass('column-'+i); }); $('tr.subquestion-list', thisQuestion).each(function(i){ $('> *', this).each(function(i){ $(this).addClass('column-'+i); }); }); // Insert the new column headers $('th.answertext:eq(1)', thisQuestion).text($('.gender-question:eq(0) span.asterisk').parent().text()); $('th.answertext:eq(2)', thisQuestion).text($('.q-1-question:eq(0) span.asterisk').parent().text()); $('th.answertext:eq(3)', thisQuestion).text($('.q-2-question:eq(0) span.asterisk').parent().text()); // Move the radios and check-boxes into the array $(genderQuestions).each(function(i) { $('td.column-2:eq('+i+')').append($('ul.answers-list', this)); }); $(q1Questions).each(function(i) { $('td.column-3:eq('+i+')').append($('ul.answers-list', this)); }); $(q2Questions).each(function(i) { $('td.column-4:eq('+i+')').append($('ul.subquestions-list', this)); }); }); </script>
.multi-question-array table.subquestions-list { width: 100%; } .multi-question-array td.answer-item ul { list-style: none; } .multi-question-array td.answer-item li { padding: 0 5px; display: inline; }
tpartner wrote: In your test group I also see a column for a check-box. Is that required?
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Identify the questions var thisQuestion = $('#question{QID}'); var genderQuestions = $(thisQuestion).nextAll('.list-radio').slice( 0, 5); var q1Questions = $(thisQuestion).nextAll('.list-radio').slice( 5, 10); // Assign some classes $(thisQuestion).addClass('multi-question-array'); $(genderQuestions).addClass('gender-question hidden-question'); $(q1Questions).addClass('q-1-question hidden-question'); // Hide the radio questions $('.hidden-question').hide(); // Insert the extra columns $('col', thisQuestion).removeAttr('width'); $('colgroup', thisQuestion).append('<col class="even"><col class="odd">'); $('thead tr', thisQuestion).append('<th class="answertext"></th><th class="answertext"></th>'); $('tr.subquestion-list', thisQuestion).append('<td class="answer-item text-item"></td><td class="answer-item text-item"></td>'); $('thead tr> *', this).each(function(i){ $(this).addClass('column-'+i); }); $('tr.subquestion-list', thisQuestion).each(function(i){ $('> *', this).each(function(i){ $(this).addClass('column-'+i); }); }); // Insert the new column headers $('th.answertext:eq(1)', thisQuestion).text($('.gender-question:eq(0) span.asterisk').parent().text()); $('th.answertext:eq(2)', thisQuestion).text($('.q-1-question:eq(0) span.asterisk').parent().text()); // Move the radios into the array $(genderQuestions).each(function(i) { $('td.column-2:eq('+i+')').append($('ul.answers-list', this)); }); $(q1Questions).each(function(i) { $('td.column-3:eq('+i+')').append($('ul.answers-list', this)); }); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Identify the questions var thisQuestion = $('#question{QID}'); var q1Question = $(thisQuestion).nextAll('.list-radio').slice( 0, 5); var genderQuestion = $(thisQuestion).nextAll('.list-radio').slice( 5, 10); // Assign some classes $(thisQuestion).addClass('multi-question-array'); $(q1Question).addClass('gender-question hidden-question'); $(genderQuestion).addClass('q-1-question hidden-question'); // Hide the radio questions $('.hidden-question').hide(); // Insert the extra columns $('col', thisQuestion).removeAttr('width'); $('colgroup', thisQuestion).append('<col class="even"><col class="odd">'); $('thead tr', thisQuestion).append('<th class="answertext"></th><th class="answertext"></th>'); $('tr.subquestion-list', thisQuestion).append('<td class="answer-item text-item"></td><td class="answer-item text-item"></td>'); $('thead tr> *', this).each(function(i){ $(this).addClass('column-'+i); }); $('tr.subquestion-list', thisQuestion).each(function(i){ $('> *', this).each(function(i){ $(this).addClass('column-'+i); }); }); // Insert the new column headers $('th.answertext:eq(1)', thisQuestion).text($('.gender-question:eq(0) span.asterisk').parent().text()); $('th.answertext:eq(2)', thisQuestion).text($('.q-1-question:eq(0) span.asterisk').parent().text()); // Move the radios into the array $(q1Question).each(function(i) { $('td.column-2:eq('+i+')').append($('ul.answers-list', this)); }); $(genderQuestion).each(function(i) { $('td.column-3:eq('+i+')').append($('ul.answers-list', this)); }); }); </script>
tpartner wrote: Switch their placement in LimeSurvey and use this script.
Code:<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Identify the questions var thisQuestion = $('#question{QID}'); var q1Question = $(thisQuestion).nextAll('.list-radio').slice( 0, 5); var genderQuestion = $(thisQuestion).nextAll('.list-radio').slice( 5, 10); // Assign some classes $(thisQuestion).addClass('multi-question-array'); $(q1Question).addClass('gender-question hidden-question'); $(genderQuestion).addClass('q-1-question hidden-question'); // Hide the radio questions $('.hidden-question').hide(); // Insert the extra columns $('col', thisQuestion).removeAttr('width'); $('colgroup', thisQuestion).append('<col class="even"><col class="odd">'); $('thead tr', thisQuestion).append('<th class="answertext"></th><th class="answertext"></th>'); $('tr.subquestion-list', thisQuestion).append('<td class="answer-item text-item"></td><td class="answer-item text-item"></td>'); $('thead tr> *', this).each(function(i){ $(this).addClass('column-'+i); }); $('tr.subquestion-list', thisQuestion).each(function(i){ $('> *', this).each(function(i){ $(this).addClass('column-'+i); }); }); // Insert the new column headers $('th.answertext:eq(1)', thisQuestion).text($('.gender-question:eq(0) span.asterisk').parent().text()); $('th.answertext:eq(2)', thisQuestion).text($('.q-1-question:eq(0) span.asterisk').parent().text()); // Move the radios into the array $(q1Question).each(function(i) { $('td.column-2:eq('+i+')').append($('ul.answers-list', this)); }); $(genderQuestion).each(function(i) { $('td.column-3:eq('+i+')').append($('ul.answers-list', this)); }); }); </script>