jQuery slider output -


i have strange problem. here fiddle: http://jsfiddle.net/m6qjc/7/

and can see, should take value of first slider, second one, calculating , print result. but, when move slider (the first one, second not doing ) fast, 1 end or another, calculates weird things. have pls. there solution pls?

$(document).ready(function () {     $("#amount_slider").slider({         orientation: "horizontal",         range: false,         min: 500,         max: 4999,         value: 500,         step: 10,                 animate: 'slow',                 slide: function (event, ui) {             $("#amountdisp").text(ui.value);             calculate();         }     });     $("#time_slider").slider({         orientation: "horizontal",         range: false,         min: 7,         max: 28,                 step: 7,         value: 7,                 animate: true,                 slide: function (event, ui) {             $("#timedisp").text(ui.value);             calculate();         }     });     function calculate() {         var amount = parseint($("#amount_slider").slider("value"));         var time = parseint($("#time_slider").slider("value"));                 var coeficient = 0;                 switch(time){                        case 7: coeficient = 1.09;break;                        case 14: coeficient = 1.15;break;                        case 21: coeficient = 1.19;break;                        case 28: coeficient = 1.25;break;                        }         var rate = amount * coeficient;         $("#result").text(rate.tofixed(2));     }    }); 

and html:

<p>money: <span id="amountdisp">500</span><div id="amount_slider"></div></p><p>time: <span id="timedisp">7</span><div id="time_slider"></div></p><p>calculated <span id="result">545</span></p> 

the slider's value has not been updated yet @ point use .slider("value") fetch it. updates after slide event has finished calculation uses previous value instead of current one.

a quick fix pass values parameters:

// in amount slider event calculate(parseint(ui.value, 10), parseint($("#time_slider").slider("value"), 10));  // in time slider event calculate(parseint($("#amount_slider").slider("value"), 10), parseint(ui.value, 10));  function calculate(amount, time) {    ... 

demo: http://jsfiddle.net/m6qjc/9/


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -