I'm a noob of HTML5 & Jquery. I've built a piece of code to calculate Loan Amount based on Term & Interest. But it seems doesn't work on my own. The numbers aren't calculated automatically and stay at 0. I appreciate any helps. Thank you everyone.
This is the Script for pasting on Wordpress Site
<script>
function pmt(rate_per_period, number_of_payments, present_value, future_value, type){
if(rate_per_period != 0.0){
// Interest rate exists
var q = Math.pow(1 + rate_per_period, number_of_payments);
return -(rate_per_period * (future_value + (q * present_value))) / ((-1 + q) * (1 + rate_per_period * (type)));
} else if(number_of_payments != 0.0){
// No interest rate, but number of payments exists
return -(future_value + present_value) / number_of_payments;
}
return 0;
}
function calcLoanezi(){
var interest;
if ($( "#invoice" ).val() =< 5000) {interest = 0.12}
else if ($( "#invoice" ).val() >= 5001 && $( "#invoice" ).val() <= 10000) {interest = 0.10}
else if ($( "#invoice" ).val() >= 10001 && $( "#invoice" ).val() <= 20000) {interest = 0.08}
else if ($( "#invoice" ).val() >= 20001 && $( "#invoice" ).val() <= 35000) {interest = 0.0725}
else if ($( "#invoice" ).val() >= 35001 && $( "#invoice" ).val() <= 60000) {interest = 0.0695}
else if ($( "#invoice" ).val() >= 60001 && $( "#invoice" ).val() <= 100000) {interest = 0.0675}
var months; // Lifetime of loan (in years)
if ($("#term").val() >=60) {interest = interest+0.01}
present = $( "#invoice" ).val(), // Present value of loan
future = 0, // Future value of loan
beginning = 0; // Calculated at start of each period
brokerage = present * 0.06;
var payment = -pmt((interest / 12), months, (Number(brokerage) + Number(present)), future, beginning);
var payment_2dp_exgst = payment.toFixed(2);
var payment_2dp_gst = ((payment*1.1)-payment).toFixed(2);
var payment_2dp_incgst = (Number(payment_2dp_exgst) + Number(payment_2dp_gst)).toFixed(2);
$( "#monthlyex" ).val("$"+payment_2dp_exgst);
$( "#monthlygst" ).val("$"+payment_2dp_gst);
$( "#monthlyinc" ).val("$"+payment_2dp_incgst);
}
$( document ).ready(function() {
$( "#invoice" ).keyup(function(){
calcLoanezi();
});
$("#term").on('change', function() {
calcLoanezi();
});
});
</script>
It doesn't show any results