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 desired loan terms. It considers factors like your gross monthly income, existing monthly debt payments, and the interest rate you anticipate. Remember, this is an estimate, and your actual borrowing capacity may vary based on lender-specific criteria and your creditworthiness.
function calculateMortgageAffordability() {
var grossMonthlyIncome = parseFloat(document.getElementById("grossMonthlyIncome").value);
var monthlyDebtPayments = parseFloat(document.getElementById("monthlyDebtPayments").value);
var downPayment = parseFloat(document.getElementById("downPayment").value);
var loanTermYears = parseInt(document.getElementById("loanTermYears").value);
var interestRate = parseFloat(document.getElementById("interestRate").value) / 100;
var annualPropertyTaxes = parseFloat(document.getElementById("propertyTaxes").value);
var annualHomeInsurance = parseFloat(document.getElementById("homeInsurance").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
if (isNaN(grossMonthlyIncome) || isNaN(monthlyDebtPayments) || isNaN(downPayment) || isNaN(loanTermYears) || isNaN(interestRate) || isNaN(annualPropertyTaxes) || isNaN(annualHomeInsurance)) {
resultDiv.innerHTML = "Please enter valid numbers for all fields.";
return;
}
// Lenders typically use a debt-to-income (DTI) ratio. A common guideline is a back-end DTI of 36% or less,
// meaning PITI (Principal, Interest, Taxes, Insurance) plus other debts shouldn't exceed 36% of gross monthly income.
// We'll use a conservative 36% DTI for this calculation.
var maxMonthlyHousingPayment = (grossMonthlyIncome * 0.36) – monthlyDebtPayments;
if (maxMonthlyHousingPayment <= 0) {
resultDiv.innerHTML = "Based on your income and debts, it may be difficult to qualify for a mortgage at this time. Consider reducing debt or increasing income.";
return;
}
// Calculate monthly PITI components
var monthlyPropertyTaxes = annualPropertyTaxes / 12;
var monthlyHomeInsurance = annualHomeInsurance / 12;
// Subtract taxes and insurance from the maximum affordable housing payment to find the maximum principal + interest payment
var maxPrincipalInterestPayment = maxMonthlyHousingPayment – monthlyPropertyTaxes – monthlyHomeInsurance;
if (maxPrincipalInterestPayment 0) {
var numerator = monthlyInterestRate * Math.pow((1 + monthlyInterestRate), numberOfPayments);
var denominator = Math.pow((1 + monthlyInterestRate), numberOfPayments) – 1;
maxLoanAmount = maxPrincipalInterestPayment * (denominator / numerator);
} else {
// Handle zero interest rate case (unlikely but for completeness)
maxLoanAmount = maxPrincipalInterestPayment * numberOfPayments;
}
// The total affordable home price is the maximum loan amount plus the down payment
var affordableHomePrice = maxLoanAmount + downPayment;
resultDiv.innerHTML = "