- Posts: 6
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
<script type="text/javascript" charset="utf-8"> $(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 1 if($('.answer-item.column-1 .inserted-select', thisQuestion).length == 0) { $('.answer-item.column-1', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">Please choose...</option>\ <option value="USD">USD</option> \ <option value="EUR">EUR</option> \ <option value="GBP">GBP</option> \ <option value="CHF">CHF</option> \ <option value="AUD">AUD</option> \ <option value="JPY">JPY</option> \ <option value="CAD">CAD</option> \ <option value="NOK">NOK</option> \ <option value="SEK">SEK</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'); } }); // Listener on column 2 inputs $('.answer-item.column-2 input:text', thisQuestion).on('keyup change', function(e) { var thisValue = $.trim($(this).val()); // Numerics only if($.isNumeric(thisValue) === false) { // Strip out non-numerics characters newValue = thisValue.replace(/\D/g,''); $(this).val(newValue).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>
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:complete',function() { var qID = {QID}; var inputNum = 1; // Define the select element (dropdown) var prov1 = '<select id="prov1" class="form-control">\ <option value="">Please choose...</option>\ <option value="USD">USD</option> \ <option value="EUR">EUR</option> \ <option value="GBP">GBP</option> \ <option value="CHF">CHF</option> \ <option value="AUD">AUD</option> \ <option value="JPY">JPY</option> \ <option value="CAD">CAD</option> \ <option value="NOK">NOK</option> \ <option value="SEK">SEK</option> \ </select>'; // Hide the text input $('#question'+qID+' .question-item:eq('+(inputNum-1)+') input[type="text"]').hide(); // Insert the select elements if($('#question'+qID+' .question-item:eq('+(inputNum-1)+') select').length == 0) { $('#question'+qID+' .question-item:eq('+(inputNum-1)+') input[type="text"]').before(prov1); } // Initially select an option if the question has already been answered $('#question'+qID+' select').each(function(i) { if($.trim($(this).next('input[type="text"]').val()) != '') { $(this).val($.trim($(this).next('input[type="text"]').val())); } }); // Listener on the dropdowns - insert selected values into hidden text input $('#question'+qID+' select').change(function() { var thisInput = $(this).next('input[type="text"]'); $(thisInput).val($(this).val()); checkconditions($(thisInput).attr('value'), $(thisInput).attr('name'), 'text'); }); // Some styles $('#question'+qID+' select').css({ 'margin':'0.3em 0 0 0' }); }); </script>
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.
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.