This calculator helps you estimate the maximum mortgage amount you can afford, considering your income, debts, and desired down payment. Understanding your mortgage affordability is a crucial first step in the home-buying process.
function calculateAffordability() {
var monthlyIncome = parseFloat(document.getElementById("monthlyIncome").value);
var monthlyDebt = parseFloat(document.getElementById("monthlyDebt").value);
var downPayment = parseFloat(document.getElementById("downPayment").value);
var interestRate = parseFloat(document.getElementById("interestRate").value);
var loanTerm = parseFloat(document.getElementById("loanTerm").value);
var resultElement = document.getElementById("result");
resultElement.innerHTML = ""; // Clear previous results
// Validate inputs
if (isNaN(monthlyIncome) || isNaN(monthlyDebt) || isNaN(downPayment) || isNaN(interestRate) || isNaN(loanTerm) ||
monthlyIncome <= 0 || monthlyDebt < 0 || downPayment < 0 || interestRate <= 0 || loanTerm <= 0) {
resultElement.innerHTML = "Please enter valid positive numbers for all fields.";
return;
}
// Lender typically allows PITI (Principal, Interest, Taxes, Insurance) to be around 28-36% of gross monthly income.
// For this calculator, we'll use a common benchmark of 28% for P&I, and assume taxes/insurance add another portion,
// but for simplicity in affordability, we'll focus on the maximum loan principal that fits within a reasonable monthly payment.
// A common debt-to-income ratio (DTI) for total obligations (including mortgage) is often around 36-43%.
// Let's use a simplified approach focusing on the maximum monthly payment a borrower can afford for P&I.
// Assumption: Max P&I payment is 28% of gross monthly income minus existing monthly debt payments.
// This is a simplification; actual lender criteria may vary.
var maxTotalMonthlyPayment = monthlyIncome * 0.36; // Using a higher DTI for total obligations, then subtracting debt
var maxMortgagePayment = maxTotalMonthlyPayment – monthlyDebt;
if (maxMortgagePayment <= 0) {
resultElement.innerHTML = "Based on your current debts and income, you may not qualify for a mortgage at this time.";
return;
}
// Calculate maximum loan amount using the mortgage payment formula:
// M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1]
// Where:
// M = Monthly Payment (maxMortgagePayment)
// P = Principal Loan Amount (what we want to find)
// i = Monthly interest rate (annual rate / 12)
// n = Total number of payments (loan term in years * 12)
var monthlyInterestRate = (interestRate / 100) / 12;
var numberOfPayments = loanTerm * 12;
var principal = maxMortgagePayment * (Math.pow(1 + monthlyInterestRate, numberOfPayments) – 1) / (monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfPayments));
var maxLoanAmount = principal;
var estimatedHomePrice = maxLoanAmount + downPayment;
resultElement.innerHTML =
"