1
votes

I would like to output two values from one noUIslider range. Using examples in the noUIslider documentation I have got to the point where I can output the same value twice, but I want one of the outputs to show a value that has been passed through a math equation (*2 or /3 for example) so that it shows a different output.

My javaScript / jQuery powers are weak so please be patient with me.

// Setting up the slider
var tooltipSlider = document.getElementById('slider-tooltip');

noUiSlider.create(tooltipSlider, {
  start: [40000],
  step: 10000,
  range: {
      'min': 40000,
      'max': 5000000
  },
  format: wNumb({
      decimals: 3,
      thousand: '.',
      prefix: '£ ',
  })
});


var tipHandles = tooltipSlider.getElementsByClassName('noUi-handle'),
  tooltips = [];

// Add divs to the slider handles.
for (var i = 0; i < tipHandles.length; i++) {
  tooltips[0] = document.createElement('div');
  tipHandles[0].appendChild(tooltips[0]);
}

// Add a class for styling
tooltips[0].className += 'score';
// Add additional markup
tooltips[0].innerHTML = '<strong>Price </strong><span></span>';
// Replace the tooltip reference with the span we just added
tooltips[0] = tooltips[0].getElementsByTagName('span')[0];

// When the slider changes, write the value to the tooltips.
tooltipSlider.noUiSlider.on('update', function (values, handle) {
  tooltips[handle].innerHTML = values[handle];
});

// When the slider changes, write the value again + maths
var rangeSliderValueElement = document.getElementById('slider-range-  value');

tooltipSlider.noUiSlider.on('update', function (values, handle) {
  rangeSliderValueElement.innerHTML = 'Price + Math: ' + values[handle];
});

I've set up a JSFiddle of what I've got so far: https://jsfiddle.net/jherit/qhgd9to0/1/

1

1 Answers

0
votes

I think you cannot do calculations because you have a prefix

prefix: '£ '

If you remove the prefix than you get the numeric value and you can do calculations with it.

https://jsfiddle.net/qhgd9to0/3/