I am trying to get multiple values to change while sliding the JQuery UI slider. Basically changing 3 different values based on the slider's number.
In this case I'm using a range of $100,000 to $2,000,000. Then I want to calculate 3 different values depending on the position of the slider.
For the first value I want to get 6% - (2.7%+ $2799).
The second value would be 6% - $5299.
And the third value would be 6% - $3799
This is what I have so far:
<div id="slider">
<div id="slider-min">$100,000</div>
<div id="slider-max">$2,000,000</div>
</div>
<input id="amount" readonly type="text">
<div class="options-wrap">
<input id="result1" readonly type="text">
<input id="result2" readonly type="text">
<input id="result3" readonly type="text">
</div>
JS
$(function() {
$( "#slider" ).slider({
range: 'min',
value: 100000,
min: 100000,
max: 2000000,
slide: function( event, ui ) {
$( "#amount" ).val( "$" + addCommas(ui.value.toString()));
}
});
$('#amount')
.val( "$" + addCommas($("#slider").slider("value")));
/// Need to add a function(s) that would change the values of
/// the following selectors $('#result1'),$('result2') and $('result3')
/// based on the position of the slider with the calculation stated above.
function addCommas(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
});
I have tried different ways to get those 3 values to change while sliding the slider, but I've frustratingly failed on every attempt. I gotta admit I'm no expert and I greatly respect those who have better knowledge on this field. Any help would be immensely appreciated.