I am trying to make a loan calculation using 3 jquery-ui sliders.
The parameters are:
Amount to borrow
Duration / Amount of months to pay back
Interest rate
While changing the sliders I would like to display the values of:
Monthly amount + Interest rate
(amount to loan / amount of months = result + (result * interest rate))Total loan amount + total Interest rate.
(Total loan amount + (total loan amount * interest rate))
Currently I only have the sliders but I have not managed to connect them together to calculate and display these values. Very thankful for your help.
Here's a Fiddle
http://jsfiddle.net/L65u9spv/
Javascript:
$(function() {
$( "#slider-toloan" ).slider({
range: "min",
value: 25000,
min: 5000,
max: 400000,
step: 5000,
slide: function( event, ui ) {
$( "#amount" ).val( "$" + ui.value );
}
});
$( "#amount" ).val( "$" + $( "#slider-toloan" ).slider( "value" ) );
$( "#slider-loanduration" ).slider({
range: "min",
value: 5,
min: 1,
max: 25,
step: 1,
slide: function( event, ui ) {
$( "#duration" ).val( ui.value );
}
});
$( "#duration" ).val( $( "#slider-loanduration" ).slider( "value" ) );
$( "#slider-rate" ).slider({
range: "min",
value: 1.85,
min: 1.75,
max: 23,
step: 0.05,
slide: function( event, ui ) {
$( "#rate" ).val( ui.value );
}
});
$( "#rate" ).val( $( "#slider-rate" ).slider( "value" ) );
});
Html:
<p>
<label for="amount">Amount to Loan:</label>
<input type="text" id="amount" readonly style="border:0; color:#f6931f; font-weight:bold;">
</p>
<div id="slider-toloan"></div>
<p>
<label for="duration">Duration Months:</label>
<input type="text" id="duration" readonly style="border:0; color:#f6931f; font-weight:bold;">
</p>
<div id="slider-loanduration"></div>
<p>
<label for="rate">Interest Rate</label>
<input type="text" id="rate" readonly style="border:0; color:#f6931f; font-weight:bold;">
</p>
<div id="slider-rate"></div>
<br /><br />
<p>To pay monthly (interest rate included): ?</p>
<span style="font-size:11px;">amount to loan / amount of months = result + (result * interest rate) </span>
<br />
<p>Total amount to pay all months (interest rate included): ?</p>
<span style="font-size:11px;">Total loan amount + (total loan amount * interest rate)</span>
Ideally this would be handled through a data-binding library like Angular, but you can just do your calculations on load, and in the slide method for each slider, so something like this:
HTML Changes:
Javascript Changes:
I forked your fiddle with my working code: http://jsfiddle.net/fnurvdt5/