Understanding how much house you can afford is a crucial first step in the home-buying process. This mortgage affordability calculator helps you estimate the maximum loan amount you might qualify for, based on your income, debts, and estimated interest rate. It's important to remember that this is an estimation, and your actual loan approval will depend on a lender's detailed review of your financial situation, credit history, and the current market conditions.
function calculateAffordability() {
var annualIncome = parseFloat(document.getElementById("annualIncome").value);
var monthlyDebt = parseFloat(document.getElementById("monthlyDebt").value);
var downPayment = parseFloat(document.getElementById("downPayment").value);
var interestRate = parseFloat(document.getElementById("interestRate").value);
var loanTermYears = parseFloat(document.getElementById("loanTermYears").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
// Validate inputs
if (isNaN(annualIncome) || annualIncome <= 0 ||
isNaN(monthlyDebt) || monthlyDebt < 0 ||
isNaN(downPayment) || downPayment < 0 ||
isNaN(interestRate) || interestRate <= 0 ||
isNaN(loanTermYears) || loanTermYears <= 0) {
resultDiv.innerHTML = "Please enter valid positive numbers for all fields.";
return;
}
// Lenders typically use a Debt-to-Income (DTI) ratio.
// A common guideline for the total housing payment (PITI – Principal, Interest, Taxes, Insurance)
// is not to exceed 28% of gross monthly income, and total debt (including housing)
// not to exceed 36% of gross monthly income. We'll use a simplified approach for affordability.
// 1. Calculate maximum total monthly debt payment allowed (e.g., 36% of gross income)
var maxTotalMonthlyDebtPayment = annualIncome / 12 * 0.36;
// 2. Calculate the maximum monthly mortgage payment (P&I only) allowed
// This is the maximum total debt payment minus existing monthly debts.
var maxMonthlyMortgagePayment = maxTotalMonthlyDebtPayment – monthlyDebt;
if (maxMonthlyMortgagePayment 0) {
var factor = Math.pow(1 + monthlyInterestRate, numberOfPayments);
principalLoanAmount = maxMonthlyMortgagePayment * (factor – 1) / (monthlyInterestRate * factor);
} else {
// Handle case of 0% interest rate (unlikely but for completeness)
principalLoanAmount = maxMonthlyMortgagePayment * numberOfPayments;
}
// 4. Calculate the estimated maximum home price
var estimatedMaxHomePrice = principalLoanAmount + downPayment;
// Display the results
resultDiv.innerHTML =
"Estimated Maximum Loan Amount: $" + principalLoanAmount.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",") + "" +
"Estimated Maximum Home Price You Can Afford: $" + estimatedMaxHomePrice.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",") + "" +
"This is an estimation based on a DTI of 36% for total debt and a loan term of " + loanTermYears + " years at " + interestRate + "% annual interest. It does not include property taxes, homeowner's insurance, or Private Mortgage Insurance (PMI), which would increase your actual monthly payment. Lenders' qualification criteria may vary.";
}
.calculator-container {
font-family: sans-serif;
border: 1px solid #ddd;
padding: 20px;
border-radius: 8px;
max-width: 600px;
margin: 20px auto;
background-color: #f9f9f9;
}
.calculator-container h2 {
text-align: center;
margin-bottom: 15px;
color: #333;
}
.calculator-container p {
line-height: 1.6;
color: #555;
margin-bottom: 20px;
}
.calculator-inputs {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 15px;
margin-bottom: 20px;
}
.input-group {
display: flex;
flex-direction: column;
}
.input-group label {
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.input-group input[type="number"] {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
box-sizing: border-box; /* Ensure padding doesn't affect width */
}
.calculator-container button {
display: block;
width: 100%;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
font-size: 18px;
cursor: pointer;
transition: background-color 0.3s ease;
margin-top: 10px;
}
.calculator-container button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 25px;
padding: 15px;
border: 1px solid #eee;
border-radius: 5px;
background-color: #fff;
text-align: center;
}
.calculator-result p {
margin-bottom: 10px;
font-size: 1.1em;
}
.calculator-result small {
font-size: 0.8em;
color: #777;
}