Understanding how much you can afford for a mortgage is a crucial first step in the home-buying process. This calculator helps you estimate your maximum affordable mortgage amount based on your income, debts, and estimated interest rates. Remember, this is an estimate, and lenders will perform their own detailed analysis.
function calculateMortgageAffordability() {
var monthlyIncome = parseFloat(document.getElementById("monthlyIncome").value);
var existingDebts = parseFloat(document.getElementById("existingDebts").value);
var downPayment = parseFloat(document.getElementById("downPayment").value);
var interestRate = parseFloat(document.getElementById("interestRate").value);
var loanTerm = parseFloat(document.getElementById("loanTerm").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = "; // Clear previous results
// — Input Validation —
if (isNaN(monthlyIncome) || monthlyIncome <= 0) {
resultDiv.innerHTML = "Please enter a valid gross monthly income.";
return;
}
if (isNaN(existingDebts) || existingDebts < 0) {
resultDiv.innerHTML = "Please enter a valid total monthly debt payment.";
return;
}
if (isNaN(downPayment) || downPayment < 0) {
resultDiv.innerHTML = "Please enter a valid down payment amount.";
return;
}
if (isNaN(interestRate) || interestRate 20) { // Assuming max 20% interest for sanity
resultDiv.innerHTML = "Please enter a valid annual interest rate (e.g., 6.5).";
return;
}
if (isNaN(loanTerm) || loanTerm 50) { // Assuming max 50 year loan for sanity
resultDiv.innerHTML = "Please enter a valid loan term in years (e.g., 30).";
return;
}
// — Mortgage Affordability Calculation —
// Lender typically uses a Debt-to-Income (DTI) ratio.
// Front-end DTI (housing costs only): usually capped at 28% of gross monthly income.
// Back-end DTI (all debts including mortgage): usually capped at 36% of gross monthly income.
// We'll use the more conservative back-end DTI to estimate maximum total debt.
var maxTotalDebtPayment = monthlyIncome * 0.36; // 36% DTI ratio
var maxMortgagePayment = maxTotalDebtPayment – existingDebts;
if (maxMortgagePayment 0) {
var numerator = monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfPayments);
var denominator = Math.pow(1 + monthlyInterestRate, numberOfPayments) – 1;
maxLoanAmount = maxMortgagePayment * (denominator / numerator);
} else { // Handle 0% interest rate, though unlikely for mortgages
maxLoanAmount = maxMortgagePayment * numberOfPayments;
}
var affordableHomePrice = maxLoanAmount + downPayment;
// — Display Results —
resultDiv.innerHTML =
"