- Posts: 8
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
Something like this?However, my requirement is to define differing steps in certain number ranges
<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="">select...</option>\ <option value="1">1</option>\ <option value="2">2</option>\ <option value="3">3</option>\ <option value="4">4</option>\ <option value="5">5</option>\ </select>'); $('.answer-item.answer_cell_X002', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">select...</option>\ <option value="1">1</option>\ <option value="3">3</option>\ <option value="5">5</option>\ </select>'); $('.answer-item.answer_cell_X003', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">select...</option>\ <option value="1">1</option>\ <option value="5">5</option>\ <option value="7">7</option>\ <option value="9">9</option>\ </select>'); $('.answer-item.answer_cell_X004', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">select...</option>\ <option value="1">1</option>\ <option value="5">5</option>\ <option value="6">6</option>\ <option value="7">7</option>\ <option value="8">8</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>
following numbers are required: 1/9, 1/7, 1/5, 1/3, 1, 3, 5, 7, 9
Of course, this is the behaviour of a question of type array.1. $('.answer-item.answer-item.answer_cell_SQ00X) is applied for the whole column. If i try answer_cell_SQ00X_SQ00X the change is not applied.
It's an array(text) and the setting is "Only numbers= Off"2. The values are shown in a separate dropdown menu. Do i need to hide the initial drop down menu then?
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); // Insert selects $('#javatbd371969X110X18161Y001 .answer-item.answer_cell_X001', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">select...</option>\ <option value="1">Y001_X001 1</option>\ <option value="2">Y001_X001 2</option>\ <option value="3">Y001_X001 3</option>\ </select>'); $('#javatbd371969X110X18161Y001 .answer-item.answer_cell_X002', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">select...</option>\ <option value="1">Red</option>\ <option value="2">Blue</option>\ <option value="3">Pink</option>\ <option value="4">Purple</option>\ </select>'); $('#javatbd371969X110X18161Y002 .answer-item.answer_cell_X001', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">select...</option>\ <option value="1">AAA</option>\ <option value="2">BBB</option>\ <option value="3">CCC</option>\ </select>'); $('#javatbd371969X110X18161Y002 .answer-item.answer_cell_X002', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">select...</option>\ <option value="1">Y002_X002 1</option>\ <option value="2">Y002_X002 2</option>\ <option value="3">Y002_X002 3</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>
This is achieved by entering the following javascript into the question text of an array(text)
It's an array(text) and the setting is "Only numbers= Off"