- 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(){ // Identify this question var thisQuestion = $('#question{QID}'); // Insert the selectelement if($('.answer-item:eq(0) .inserted-select', thisQuestion).length == 0) { $('.answer-item:eq(0)', thisQuestion).addClass('with-select').append('<select id="inserted-select-{QID}" class="inserted-select form-control list-question-select">\ <option value="">Please choose...</option>\ <option value="Yes">Yes</option>\ <option value="No">No</option>\ <option value="Do not know">Do not know</option>\ </select>'); } // Listeners on select elements $('#inserted-select-{QID}').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 var inputText = $.trim($('input:text:eq(0)', thisQuestion).val()); $('select.inserted-select', thisQuestion).val(inputText); // Clean-up styles $('select.inserted-select', thisQuestion).css({ 'width': 'auto', 'max-width': '100%' }); $('.with-select input:text', thisQuestion).css({ 'position': 'absolute', 'left': '-9999em' }); }); </script>
I said "You cannot dynamically add answers to a list-dropdown question". You can dynamically modify a <select> element that you insert into a text-short (or array) via JavaScript.This is really helpful, since you told me we cannot populate dropdown