Simple JQuery Mortgage Calculator

Servee is moving into real estate territory, more details to come, but I've made this simple mortgage calculator. Free to use, no warranty, etc.

Here is the code for your copy and paste, check the example below. It requires Jquery to function. My styles also may mess up the line breaks in the HTML, but the JS is all pretty short, so it's not a big deal.

<!-- if you don't have jquery -->
<script type='text/javascript' src='http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js'></script>

<!--The following formula is used to calculate the fixed monthly payment (P) required to fully amortize a loan of L dollars over a term of n months at a monthly interest rate of c. [If the quoted rate is 6%, for example, c is .06/12 or .005].

P = L[c(1 + c)^n]/[(1 + c)^n - 1]-->
<h3>Mortgage Calculator</h3>
<form >
<p> <input type="text" name="mcPrice" id="mcPrice" class="mortgageField" />
Sale price ($)
</p>
<p> <input type="text" name="mcDown" id="mcDown" class="mortgageField" />
Down payment (%)</p>
<p> <input type="text" name="mcRate" id="mcRate" class="mortgageField" />
Interest Rate (%)</p>
<p> <input type="text" name="mcTerm" id="mcTerm" class="mortgageField" />
Term (years)</p>
<button class="smallButton" id="mortgageCalc" onclick="return false">Calculate Monthly Payment</button>
<input type="text" name="mcPayment" id="mcPayment" class="mortgageAnswer" />
</form>
<script type="text/javascript">
$("#mortgageCalc").click(function(){
var L,P,n,c,dp;
L = parseInt($("#mcPrice").val());
n = parseInt($("#mcTerm").val()) * 12;
c = parseFloat($("#mcRate").val())/1200;
dp = 1 - parseFloat($("#mcDown").val())/100;
L = L * dp;
P = (L*(c*Math.pow(1+c,n)))/(Math.pow(1+c,n)-1);
if(!isNaN(P))
{
$("#mcPayment").val(P.toFixed(2));
}
else
{
$("#mcPayment").val('There was an error');
}
return false;
});
</script>

Mortgage Calculator Example

Sale price ($)

Down payment (%)

Interest Rate (%)

Term (years)



Comments and Messages

I won't ever give out your email address. I don't publish comments but if you'd like to write to me then you could use this form.

Issac Kelly