- Posts: 4
- 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 a select into the last row var insertRow = $('.answer-item:last', thisQuestion); $(insertRow).addClass('with-select'); if($('.inserted-select', insertRow).length == 0) { $('.answer-item:last input:text', thisQuestion).after('<select class="inserted-select form-control list-question-select">\ <option value="">Please choose...</option>\ <option value="1">Yes</option>\ <option value="2">No</option>\ <option value="3">Do not know</option>\ </select>'); } // Listeners $('.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'); } }); // Returning to page $('.with-select input:text', thisQuestion).each(function(i) { var thisRow = $(this).closest('.answer-item'); var inputText = $.trim($(this).val()); var selectval = $('select.inserted-select option', thisRow).filter(function () { return $(this).html() == inputText; }).val(); $('select.inserted-select', thisRow).val(selectval); }); // Clean-up styles $('.with-select input:text', thisQuestion).css({ 'position': 'absolute', 'left': '-9999em' }); }); </script>