JavaScript returning NaN value -
i have 2 ui-slider, , have calculation on slide callback, it's returning nan value
$( document ).ready(function() { $("#amount").slider({ range: "min", value: 160000, min: 10000, max: 400000, step: 1, slide: function(event, ui) { var interest = 0.0325; var amount = parseint(ui.value); var temp1 = amount * (interest / 12) / (1 - math.pow(1 + (interest / 12), -(years * 12))); $('#currentamount').val(amount); $('#monthly').text(math.round(temp1)); } }); $("#years").slider({ range: "min", value: 8, min: 1, max: 12, step: 1, slide: function(event, ui) { var interest = 0.0325; var years = parseint(ui.value); var temp1 = amount * (interest / 12) / (1 - math.pow(1 + (interest / 12), -(years * 12))); $('#yearsval').text(years); $('#monthly').text(math.round(temp1)); } }); });
i made fiddle: http://jsfiddle.net/kristianladd/w0xayf7t/
the reason why put on slide callback, if slide either of two, calculate.
simply read status other slider whenever slide called:
$( document ).ready(function() { $("#amount").slider({ range: "min", value: 160000, min: 10000, max: 400000, step: 1, slide: function(event, ui) { var years = $('#years').slider("option", "value"); var interest = 0.0325; var amount = parseint(ui.value); var temp1 = amount * (interest / 12) / (1 - math.pow(1 + (interest / 12), -(years * 12))); $('#currentamount').val(amount); $('#monthly').text(math.round(temp1)); } }); $("#years").slider({ range: "min", value: 8, min: 1, max: 12, step: 1, slide: function(event, ui) { var amount = $('#amount').slider("option", "value"); var interest = 0.0325; var years = parseint(ui.value); var temp1 = amount * (interest / 12) / (1 - math.pow(1 + (interest / 12), -(years * 12))); $('#yearsval').text(years); $('#monthly').text(math.round(temp1)); } }); });
Comments
Post a Comment