- Posts: 28
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
Please Log in to join the conversation.
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); // Insert selects $('.answer-item.answer_cell_X001', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">...</option>\ <option value="1">hourly</option>\ <option value="2">monthly</option>\ <option value="4">yearly</option>\ <option value="9">I don\'t know</option>\ </select>'); // Listeners $('.inserted-select', thisQuestion).on('change', function(i) { if($(this).val() != '') { $(this).closest('.answer-item').find('input:text').val($('option:selected', this).val()).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_X001')) { handleColumnX002($(this)); } }); function handleColumnX002(thisSelect) { var thisRow = $(thisSelect).closest('tr.subquestion-list'); var item3 = $('.answer_cell_X002', thisRow); if($(thisSelect).val() < '9') { $('input', 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()); $('input:text', thisCell).val(inputText); }); // Clean-up styles $('select.inserted-select', thisQuestion).css({ 'max-width': '100%' }); $('.with-select input:text', thisQuestion).css({ 'position': 'absolute', 'left': '-9999em' }); }); </script>
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}'); // Insert selects $('.answer-item.answer_cell_X001', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">...</option>\ <option value="1">Stunde</option>\ <option value="2">Monat</option>\ <option value="3">Jahr</option>\ <option value="9">Weiß nicht</option>\ </select>'); // Listeners $('.inserted-select', thisQuestion).on('change', function(i) { if($(this).val() != '') { $(this).closest('.answer-item').find('input:text').val($('option:selected', this).val()).trigger('change'); } else { $(this).closest('.answer-item').find('input:text').val('').trigger('change'); } // 2nd column conditional on 1st column if($(this).closest('.answer-item').hasClass('answer_cell_X001')) { handleColumnX002($(this)); } }); function handleColumnX002(thisSelect) { var thisRow = $(thisSelect).closest('tr.subquestion-list'); var item2 = $('.answer_cell_X002', thisRow); if($(thisSelect).val() < '9') { $('input:text', item2).prop('readonly', false); $('input:text', item2).val('').trigger('change'); } else { $('input:text', item2).val('').prop('readonly', true); $('input:text', item2).val('- NA -').trigger('change'); } } // Returning to page $('.with-select input:text', thisQuestion).each(function(i) { var thisCell = $(this).closest('.answer-item'); var inputText = $.trim($(this).val()); $('select.inserted-select', thisCell).val(inputText); }); // Clean-up styles $('select.inserted-select', thisQuestion).css({ 'max-width': '100%' }); $('.with-select input:text', thisQuestion).css({ 'position': 'absolute', 'left': '-9999em' }); }); </script>
Please Log in to join the conversation.
Please Log in to join the conversation.
That should be the least thing - to change this variable in the calculation or even insert an equation to set a variable of the desired type and name.this affected the calculations at the later stages
Of course. This is simple validation.is it possible to add a warning being shown when a respondent clicks the button and fills the boxes at the same time
<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="">--Bitte, wählen--</option>\ <option value="1">Stunde</option>\ <option value="2">Monat</option>\ <option value="3">Jahr</option>\ <option value="4">Keine Ahnung</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.