- Posts: 9
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
Maybe you use the wrong script.but I could not apply it to specific columns.
Please Log in to join the conversation.
Please Log in to join the conversation.
You do not substitute QID. {QID} is a placeholder that is filled automatically with the actual question ID (curly brackets -> ExpressionScript)where to substitute (QID)
An easy way is to code theand identifying sub-questions numbers (for X and Y axis)
so I can have the same drop down in every other column and in all of my rows
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); // Insert selects $('.answer-item', thisQuestion).append('<select class="inserted-select form-control list-question-select">\ <option value="">Please choose...</option>\ <option value="1">very good</option>\ <option value="2">good</option>\ <option value="3">neither / nor</option>\ <option value="4">poor</option>\ <option value="5">very poor</option>\ <option value="6">DK/NA</option>\ </select>'); // Listeners $('.inserted-select', thisQuestion).on('change', function(i) { if($(this).val() != '') { $(this).closest('.answer-item').find('input:text').val($.trim($(this).val())).trigger('change'); } else { $(this).closest('.answer-item').find('input:text').val('').trigger('change'); } }); // Returning to page $('input:text', thisQuestion).each(function(i) { var thisCell = $(this).closest('.answer-item'); var inputVal = $.trim($(this).val()); $('select.inserted-select', thisCell).val(inputVal); }); // Clean-up styles $('select.inserted-select', thisQuestion).css({ 'max-width': '100%' }); $('input:text', thisQuestion).css({ 'position': 'absolute', 'left': '-9999em' }); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); // Insert selects $('.answer-item.answer_cell_X001', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">...</option>\ <option value="1">Mère</option>\ <option value="2">Pére</option>\ <option value="3">Soeur</option>\ <option value="4">Frère</option>\ </select>'); $('.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">masculin</option>\ <option value="2">femelle</option>\ <option value="3">autre chose </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).each(function(i) { var thisCell = $(this).closest('.answer-item'); var inputText = $.trim($(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>
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); // Column specific classes $('tr.subquestion-list', thisQuestion).each(function(i) { $('th, td', this).each(function(i) { $(this).addClass('column-'+i); }); }); // Insert selects into column 2 if($('.answer-item.column-2 .inserted-select', thisQuestion).length == 0) { $('.answer-item.column-2', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">Please choose...</option>\ <option value="M">M</option>\ <option value="Q">Q</option>\ <option value="U">U</option>\ <option value="W">W</option>\ <option value="X">X</option>\ <option value="Z">Z</option>\ </select>'); } // Insert selects into column 4 if($('.answer-item.column-4 .inserted-select', thisQuestion).length == 0) { $('.answer-item.column-4', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">Please choose...</option>\ <option value="A">A</option>\ <option value="B">B</option>\ <option value="C">C</option>\ <option value="D">D</option>\ <option value="E">E</option>\ <option value="F">F</option>\ </select>'); } // Listeners on select elements $('.inserted-select', thisQuestion).on('change', function(i) { if($(this).val() != '') { $(this).closest('.answer-item').find('input:text').val($.trim($('option:selected', this).text())).trigger('keyup'); } else { $(this).closest('.answer-item').find('input:text').val('').trigger('keyup'); } }); // Returning to page $('.with-select input:text', thisQuestion).each(function(i) { var thisCell = $(this).closest('.answer-item'); var inputText = $.trim($(this).val()); var selectval = $('select.inserted-select option', thisCell).filter(function () { return $(this).html() == inputText; }).val(); $('select.inserted-select', thisCell).val(selectval); }); // 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.
Sorry, why do I write1) var thisQuestion = $('#SQ004{3038}'); Is this correct?
Where:
1) #question (this my subquestion (X axis)
2) {QID} refers to my ID question number?
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.