function calculateMortgage() {
// Get Input Values
var homePrice = parseFloat(document.getElementById("mcHomePrice").value);
var downPayment = parseFloat(document.getElementById("mcDownPayment").value);
var interestRate = parseFloat(document.getElementById("mcInterestRate").value);
var loanTermYears = parseInt(document.getElementById("mcLoanTerm").value);
var annualTax = parseFloat(document.getElementById("mcPropertyTax").value);
var annualInsurance = parseFloat(document.getElementById("mcHomeInsurance").value);
var monthlyHOA = parseFloat(document.getElementById("mcHOA").value);
// Validate Inputs
if (isNaN(homePrice) || homePrice <= 0) homePrice = 0;
if (isNaN(downPayment) || downPayment < 0) downPayment = 0;
if (isNaN(interestRate) || interestRate < 0) interestRate = 0;
if (isNaN(annualTax) || annualTax < 0) annualTax = 0;
if (isNaN(annualInsurance) || annualInsurance < 0) annualInsurance = 0;
if (isNaN(monthlyHOA) || monthlyHOA 0) {
if (interestRate === 0) {
monthlyPrincipalInterest = principal / numberOfPayments;
} else {
monthlyPrincipalInterest = principal * (monthlyRate * Math.pow(1 + monthlyRate, numberOfPayments)) / (Math.pow(1 + monthlyRate, numberOfPayments) – 1);
}
}
// Calculate Other Components
var monthlyTax = annualTax / 12;
var monthlyInsurance = annualInsurance / 12;
// Total Monthly Payment
var totalMonthlyPayment = monthlyPrincipalInterest + monthlyTax + monthlyInsurance + monthlyHOA;
// Total Interest and Cost
var totalPaymentOverLife = monthlyPrincipalInterest * numberOfPayments;
var totalInterest = totalPaymentOverLife – principal;
// Calculate Payoff Date
var today = new Date();
var payoffDate = new Date(today.setMonth(today.getMonth() + numberOfPayments));
var options = { month: 'long', year: 'numeric' };
var payoffDateString = payoffDate.toLocaleDateString('en-US', options);
// Update UI Results
var formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2
});
document.getElementById("mcTotalMonthly").innerText = formatter.format(totalMonthlyPayment);
document.getElementById("mcPrincipalInterest").innerText = formatter.format(monthlyPrincipalInterest);
document.getElementById("mcMonthlyTax").innerText = formatter.format(monthlyTax);
document.getElementById("mcMonthlyIns").innerText = formatter.format(monthlyInsurance);
document.getElementById("mcMonthlyHOA").innerText = formatter.format(monthlyHOA);
document.getElementById("mcLoanAmount").innerText = formatter.format(principal);
document.getElementById("mcTotalInterest").innerText = formatter.format(totalInterest);
document.getElementById("mcPayoffDate").innerText = payoffDateString;
// Show Result Box
document.getElementById("mcResultBox").style.display = "block";
}
Understanding Your Mortgage Payment
Calculating your monthly mortgage payment is the first step in determining how much house you can afford. While the sticker price of a home gives you a general idea, your actual monthly financial obligation includes several components known collectively as PITI: Principal, Interest, Taxes, and Insurance.
1. Principal and Interest
The core of your mortgage payment is the repayment of the money you borrowed (Principal) plus the cost of borrowing that money (Interest). In the early years of a standard amortization schedule, a larger portion of your payment goes toward interest. Over time, as the principal balance decreases, more of your payment goes toward reducing the debt.
Our calculator uses the standard amortization formula:
M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1 ]
Where 'M' is your total monthly payment, 'P' is the principal loan amount, 'i' is your monthly interest rate, and 'n' is the number of months required to repay the loan.
2. Property Taxes and Insurance
Most lenders require borrowers to pay property taxes and homeowners insurance as part of their monthly payment. These funds are typically held in an escrow account.
Property Taxes: Charged by your local government based on the assessed value of your home. These fund local services like schools and emergency response.
Homeowners Insurance: Protects your property against damage from fire, theft, and other perils. Lenders mandate this to protect their collateral.
3. HOA Fees
If you are buying a condo or a home in a planned community, you will likely have to pay Homeowners Association (HOA) fees. While these are usually paid directly to the association rather than the lender, our calculator includes them to give you a complete picture of your monthly housing expenses.
How Interest Rates Affect Your Buying Power
Even a small change in interest rates can significantly impact your monthly payment and the total cost of the loan. For example, on a $300,000 loan, a 1% increase in interest rate can raise your monthly payment by hundreds of dollars and cost tens of thousands more in interest over the life of a 30-year loan.
Use the Mortgage Payment Calculator above to experiment with different down payment amounts and interest rate scenarios to find a financing plan that fits your budget.