DOWNLOAD: Simple Mortgage Payment Calculator
The Simple Mortgage Payment Calculator script can be used for free on your website. You can even modify the code to suit your needs. Our only request is that you link back to Raving Roo (http://ravingroo.com) from your website.
The Simple Mortgage Payment Calculator script exists in three parts, (1) HTML code, (2) CSS code, (3) JavaScript code. Expand each of the sections below to copy the code.
Get the code:
<div class="smpc-div">
<form name=mortgagecalc method=POST>
<p>How much will you be borrowing?<br>
<input type=text onkeypress="return validNumber(event)" name=loan size=10> <span class="smpc-error" id="loanError"></span></p>
<p>What will be the term of this mortgage (in years)?<br>
<input type=text onkeypress="return validNumber(event)" name=years size=5> <span class="smpc-error" id="yearsError"></span></p>
<p>What will be the interest rate?<br>
<input type=text onkeypress="return validNumber(event)" name=rate size=5> <span class="smpc-error" id="rateError"></span></p>
<input type=button onClick="return myPayment()" value=Calculate> <input type=button onClick="return myPaymentReset()" value=Reset>
</form>
<small>Instructions: Enter numbers and decimal points. No commas or other characters.</small>
<p class="smpc-monthlypayment" id="monthlyPayment"> </p>
<p class="smpc-friendlyreminder" id="friendlyReminder">This is your principal + interest payment, or in other words, what you send to the bank each month. But remember, you will also have to
budget for homeowners insurance, real estate taxes, and if you are unable to afford a 20% down payment, Private Mortgage Insurance (PMI).
These additional costs could increase your monthly outlay by as much 50%, sometimes more.</p>
</div>
/* START - Simple Mortage Payment Calculator */
.smpc-div {
background-color: #f9f9f9;
border:1px solid #cccccc;
padding:15px;
}
.smpc-error {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color:#ca0000;
}
.smpc-monthlypayment {
margin-top:15px;
font-size:24px;
color:#ca0000;
}
.smpc-friendlyreminder {
display:none;
}
/* END - Simple Mortage Payment Calculator */
/*!
* Raving Roo - Simple Mortgage Payment Calculator (SMPC) v1.0
* Copyright 2014 by David K. Sutton
*
* You are free to use this script on your website.
* While not required, it would be much appreciated if you could link back to http://ravingroo.com
*/
function validNumber(fieldinput){
var unicode=fieldinput.charCode? fieldinput.charCode : fieldinput.keyCode;
if ((unicode!=8) && (unicode!=46)) { //if the key isn't the backspace key (which we should allow)
if (unicode<48||unicode>57) //if not a number
return false; //disable key press
}
}
function myPayment()
{
// Reset error messages to blank
document.getElementById('loanError').innerHTML = '';
document.getElementById('yearsError').innerHTML = '';
document.getElementById('rateError').innerHTML = '';
// Form validation checking
if ((document.mortgagecalc.loan.value === null) || (document.mortgagecalc.loan.value.length === 0) || (isNaN(document.mortgagecalc.loan.value) === true))
{
document.getElementById('monthlyPayment').innerHTML = 'Please enter the missing information.';
document.getElementById('loanError').innerHTML = 'Numeric value required. Example: 165000';
} else if ((document.mortgagecalc.years.value === null) || (document.mortgagecalc.years.value.length === 0) || (isNaN(document.mortgagecalc.years.value) === true))
{
document.getElementById('monthlyPayment').innerHTML = 'Please enter the missing information.';
document.getElementById('yearsError').innerHTML = 'Numeric value required. Example: 30';
} else if ((document.mortgagecalc.rate.value === null) || (document.mortgagecalc.rate.value.length === 0) || (isNaN(document.mortgagecalc.rate.value) === true))
{
document.getElementById('monthlyPayment').innerHTML = 'Please enter the missing information.';
document.getElementById('rateError').innerHTML = 'Numeric value required. Example: 5.25';
} else
{
// Set variables from form data
var loanprincipal = document.mortgagecalc.loan.value;
var months = document.mortgagecalc.years.value * 12;
var interest = document.mortgagecalc.rate.value / 1200;
// Calculate mortgage payment and display result
document.getElementById('monthlyPayment').innerHTML = 'Your monthly mortgage payment will be ' + '$' + (loanprincipal * interest / (1 - (Math.pow(1/(1 + interest), months)))).toFixed(2)+'.';
document.getElementById('friendlyReminder').style.display = 'block';
}
// payment = principle * monthly interest/(1 - (1/(1+MonthlyInterest)*Months))
}
function myPaymentReset()
{
// Reset everything to default/null/blank
document.getElementById('monthlyPayment').innerHTML = 'Values reset';
document.getElementById('friendlyReminder').style.display = 'none';
document.getElementById('loanError').innerHTML = '';
document.getElementById('yearsError').innerHTML = '';
document.getElementById('rateError').innerHTML = '';
document.mortgagecalc.loan.value = null;
document.mortgagecalc.years.value = null;
document.mortgagecalc.rate.value = null;
}