- 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 selects $('.answer-item.answer_cell_X1', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">Bitte auswählen, falls zutreffend...</option>\ <option value="1">zu Fuß</option>\ <option value="2">Fahrrad</option>\ <option value="3">Pkw (Benzin/Diesel) als Fahrer*in</option>\ <option value="4">Pkw mit alternativem Antrieb als Fahrer*in (z. B. Elektro, Wasserstoff)</option>\ <option value="5">Pkw (Benzin/Diesel) als Mitfahrer*in</option>\ <option value="6">Pkw mit anderem alternativem Antrieb als Mitfahrer*in (z.B. Elektro, Wasserstoff)</option>\ <option value="7">Bus</option>\ <option value="8">Straßenbahn, U-Bahn</option>\ <option value="9">Bahn (inkl. Schnell-/ Lokalbahn)</option>\ <option value="10">Taxi</option>\ <option value="11">Sonstiges (z.B. E-Scooter, (E-)Motorrad)</option>\ <option value="12">Elektro-Fahrrad</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 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> <p>Hier steht ein Erklärungstext</p>
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.