- Posts: 27
- Thank you received: 1
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var thisQuestion = $('#question{QID}'); $('.ui-slider', thisQuestion).on('slide', function(event, ui) { var thisQuestion = $(this).closest('.numeric-multi'); var thisRow = $(this).closest('li.answer-item'); var otherRow = $('li.answer-item', thisQuestion).not(thisRow); $('.ui-slider', otherRow).slider('option', 'value', 100-ui.value); $('input.text', otherRow).val($('.ui-slider', otherRow).slider('option', 'value').toString().replace(/\./, LSvar.sLEMradix)); $('.slider_callout', otherRow).text($('input.text', otherRow).val()); }); }); </script>
The sample survey is for LS 2.06. What is your version?I've downloaded your sample survey as attached in your reply but it's not working for me.
I don't think you can achieve that with 4 sliders. If one slider is moved, what do you expect to do to the other 3? Move them all a little bit? I don't see that as user-friendly or intuitive.I'm looking at the same solution but maybe with 3-4 sliders all accumulated to 100%...
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var thisQuestion = $('#question{QID}'); $('input[type="text"]', thisQuestion).on('slide slideStop', function(event, ui) { var otherSlider = $('input[type="text"]', thisQuestion).not(this); otherSlider.bootstrapSlider('setValue', 100 - $(this).val()); }); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify this question var thisQuestion = $('#question{QID}'); $('body').on('slide slideStop', '#question{QID} input.answer-item', function(event) { var thisName = $(this).attr('name').replace('slid', ''); var otherSlider = $('input.answer-item', thisQuestion).filter(function () { return $(this).attr('name').replace('slid', '') != thisName; }).first(); var psSeparator = $(this).attr('data-ps-separator'); var psStep = $(this).attr('data-ps-step'); var sliderVal = Number($(this).val().replace(psSeparator, '.')); // Move the slider var otherName = $(otherSlider).attr('name').replace('slid', ''); window.activeSliders['s'+otherName].getSlider().setValue(100-sliderVal); // Handle the inputs var displayValue = $(otherSlider).val().toString().replace('.', psSeparator); $(otherSlider).val(displayValue); $(otherSlider).closest('li.answer-item').find('input.em_sq_validation').val(displayValue); // Fire Expression Manager ExprMgr_process_relevance_and_tailoring('keyup', otherName, 'change'); }); }); </script>