JavaScript question On this form you will calcuate the payme
JavaScript question:
On this form, you will calcuate the payment on a loan. JavaScript does not have a PMT function like VB or Excel. Thus, you will have to use the formula to get the answer. If you don\'t remember the formula to calculate a payment, visit http://www.financeformulas.net/Loan_Payment_Formula.html
Inputs
Initial Loan Amount
Number of Periods (Years)
Interest Rate (Years)
Output
Payment amount
So that you can check your work, the payment on a $100,000 loan for 10 years at 6% interest is $1,110.21. Note, when calculating the payment, the user enters the input values in years. However, the payment should be calculated using values expressed in months. Thus, you must multiply the number of periods by 12 to express the value in months. You need to divide the interest rate by 12 to express the annual interest rate as a monthly interest rate. When we say 6% interest for 10 years, the interest is typically compounded monthly. So the actual values are 6%/12 and 10 years * 12.
For reference: http://www.bankrate.com/calculators/mortgages/loan-calculator.aspx?loanAmount=100000&years=10.000&terms=120&interestRate=6.000&loanStartDate=04+Nov+2016&show=false&showRt=true&prods=388&monthlyAdditionalAmount=0&yearlyAdditionalAmount=0&yearlyPaymentMonth=&oneTimeAdditionalPayment=0&oneTimeAdditionalPaymentInMY=&ic_id=mtg_loan_calc_calculate_btn
Loan Calculator This loan calculator will help you determine the monthly payments on a loan. Simply enter the loan amount, term and interest rate in the fields below and click calculate. This calculator can be used for mortgage, auto, or any other fixed loan types. $100,000 1,110.21 Loan amount MONTHLY PAYMENTS Loan term in years 10.000 or Term in months 120 Interest rate per year % 6.000 TODAY\'S RATES Loan start date 04 Nov 2016 Interest Principal CALCULATE SHOW AMORTIZATION SCHEDULE Advertiser Disclosure Lock in Monthly Payment of: $1,110.21 or lessSolution
<html>
<head><title>Loan Monthly EMI Calculator</title></head>
<body bgcolor=\"white\">
<form name=\"monthlyemi\">
<table>
<tr><td colspan=\"3\"><b>Enter Loan Information:</b></td></tr>
<tr>
<td>Initial loan amount:</td>
<td><input type=\"text\" name=\"principal\" size=\"12\"
onchange=\"calculate();\"></td>
</tr>
<tr>
<td>Interest Rate (Years):</td>
<td><input type=\"text\" name=\"interest\" size=\"12\"
onchange=\"calculate();\"></td>
</tr>
<tr>
<td>Number of Periods (Years):</td>
<td><input type=\"text\" name=\"years\" size=\"12\"
onchange=\"calculate();\"></td>
</tr>
<tr><td colspan=\"3\">
<input type=\"button\" value=\"Compute\" onclick=\"calculate();\">
</td></tr>
<tr><td colspan=\"3\">
<b></b>
</td></tr>
<tr>
<td>Payment amount (Monthly):</td>
<td><input type=\"text\" name=\"payment\" size=\"12\"></td>
</tr>
</table>
</form>
<script language=\"JavaScript\">
function calculate() {
var principal = document.monthlyemi.principal.value;
var interest = document.monthlyemi.interest.value / 100 / 12;
var payments = document.monthlyemi.years.value * 12;
// Compute the monthly payment figure.
var x = Math.pow(1 + interest, payments);
var monthly = (principal*x*interest)/(x-1);
// Check that the result is a finite number. If so, display the results.
if (!isNaN(monthly) &&
(monthly != Number.POSITIVE_INFINITY) &&
(monthly != Number.NEGATIVE_INFINITY)) {
document.monthlyemi.payment.value = round(monthly);
document.monthlyemi.total.value = round(monthly * payments);
document.monthlyemi.totalinterest.value =
round((monthly * payments) - principal);
}
// Otherwise, the user\'s input was probably invalid, so don\'t
// display anything.
else {
document.monthlyemi.payment.value = \"\";
document.monthlyemi.total.value = \"\";
document.monthlyemi.totalinterest.value = \"\";
}
}
function round(x) {
return Math.round(x*100)/100;
}
</script>
</body>
</html>

