- Posts: 8
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); // Insert selects into column 2 $(' .answer_cell_S2b1', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="1">France</option>\ <option value="2">Allemagne</option>\ <option value="3">Suisse</option>\ <option value="4">Autre</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('change'); } else { $(this).closest('.answer-item').find('input:text').val('').trigger('change'); } // 3rd column conditional on 2nd column if($(this).closest('.answer-item').hasClass('answer_cell_S2b1')) { handleColumn3($(this)); } }); function handleColumn3(thisSelect) { var thisRow = $(thisSelect).closest('tr.subquestion-list'); var item3 = $('.answer_cell_S2b2', thisRow); if($(thisSelect).val() == '1') { $('input:text', item3).prop('disabled', false); } else { $('input:text', item3).val('').prop('disabled', true); // $('input:text', item3).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()); var selectval = $('select.inserted-select option', thisCell).filter(function () { return $(this).html() == inputText; }).val(); $('select.inserted-select', thisCell).val(selectval); // 3rd column conditional on 2nd column if($(this).closest('.answer-item').hasClass('answer_cell_S2b1')) { handleColumn3($('select.inserted-select', thisCell)); } }); // Clean-up styles $('select.inserted-select', thisQuestion).css({ 'max-width': '100%' }); $('.with-select input:text', thisQuestion).css({ 'position': 'absolute', 'left': '-9999em' }); }); </script>