- Posts: 19
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
Please Log in to join the conversation.
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify the questions var qArrayID = {QID}; var qArray = $('#question'+qArrayID); var qMultiText = qArray.nextAll('.multiple-short-txt:eq(0)'); // Hide the multi-short-text question $(qMultiText).hide(); // Remove the core column widths $('table.questions-list col:not(.col-answers)', qArray).css('width', 'auto'); // Insert the header cells $('table.questions-list thead td:eq(0)', qArray).after('<th class="answer-text inserted-column-label" /></th>'); $('.inserted-column-label', qArray).css('width','30%'); // Insert the answer row cells $('tr.answers-list', qArray).each(function(i) { $('.answertext', this).after('<td class="answer-item text-item"></td>'); }); // Load the column label for the text inputs $('.inserted-column-label:eq(0)', qArray).text($('.ls-label-question', qMultiText).text()); // Loop through the multi-short-text sub-questions $('li.answer-item', qMultiText).each(function(i) { // Move the text inputs into the array $('input[type="text"]', this).appendTo($('tr.answers-list:eq('+i+') .text-item', qArray)); }); }); </script>
Please Log in to join the conversation.
Please Log in to join the conversation.
No, this is a different approach.I have now an array(text) as the first question and list(dropdown) as the 2nd. What do I need to change in the javascript code?
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); // Insert selects $('.answer-item.answer_cell_X002', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">...</option>\ <option value="1">Calculation</option>\ <option value="2">Estimation</option>\ <option value="3">Don\'t know</option>\ </select>'); // Listeners $('.inserted-select', thisQuestion).on('change', function(i) { if($(this).val() != '') { $(this).closest('.answer-item').find('input:text').val($('option:selected', this).val()).trigger('change'); } else { $(this).closest('.answer-item').find('input:text').val('').trigger('change'); } }); // Returning to page $('.with-select input:text', thisQuestion).[url=https://www.php.net/each]each[/url](function(i) { var thisCell = $(this).closest('.answer-item'); var inputText = $.[url=https://www.php.net/trim]trim[/url]($(this).val()); $('select.inserted-select', thisCell).val(inputText); }); // Clean-up styles $('select.inserted-select', thisQuestion).css({ 'max-width': '100%' }); $('.with-select input:text', thisQuestion).css({ 'position': 'absolute', 'left': '-9999em' }); }); </script>
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.