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 mortgage loan you might qualify for based on your income, debts, and a few other key financial factors. It's a great tool to set a realistic budget before you start browsing for your dream home.
.calculator-container {
font-family: sans-serif;
border: 1px solid #ccc;
padding: 20px;
border-radius: 8px;
max-width: 600px;
margin: 20px auto;
background-color: #f9f9f9;
}
.calculator-container h2 {
text-align: center;
color: #333;
margin-bottom: 15px;
}
.calculator-container p {
color: #555;
line-height: 1.6;
margin-bottom: 25px;
text-align: justify;
}
.input-group {
margin-bottom: 15px;
display: flex;
flex-direction: column;
}
.input-group label {
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.input-group input {
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1rem;
}
button {
background-color: #007bff;
color: white;
padding: 12px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 1.1rem;
width: 100%;
margin-top: 10px;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
#result {
margin-top: 25px;
padding: 15px;
background-color: #e9ecef;
border: 1px solid #ced4da;
border-radius: 5px;
text-align: center;
font-size: 1.2rem;
color: #333;
}
#result strong {
color: #28a745;
}
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 loanTerm = parseFloat(document.getElementById("loanTerm").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
if (isNaN(annualIncome) || isNaN(monthlyDebt) || isNaN(downPayment) || isNaN(interestRate) || isNaN(loanTerm)) {
resultDiv.innerHTML = "Please enter valid numbers for all fields.";
return;
}
// Lender typically uses Debt-to-Income (DTI) ratio.
// A common guideline is that total housing costs (PITI – Principal, Interest, Taxes, Insurance)
// should not exceed 28-36% of gross monthly income, and total debt (including housing)
// should not exceed 36-43% of gross monthly income.
// We'll use a simplified approach based on maximum monthly payment capacity.
// Let's assume a maximum total debt-to-income ratio (including mortgage) of 43%.
// And a maximum housing-only debt-to-income ratio of 30% for a conservative estimate.
var grossMonthlyIncome = annualIncome / 12;
var maxTotalMonthlyPayment = grossMonthlyIncome * 0.43; // 43% of gross income for all debt
var maxHousingPayment = grossMonthlyIncome * 0.30; // 30% of gross income for housing only
var allowedMonthlyDebt = maxTotalMonthlyPayment – monthlyDebt;
// The actual maximum monthly mortgage payment the borrower can afford
var maxMortgagePayment = Math.min(allowedMonthlyDebt, maxHousingPayment);
if (maxMortgagePayment 0 && n > 0) {
// Formula for present value of an annuity: PV = PMT * [1 – (1 + r)^-n] / r
maxLoanAmount = maxMortgagePayment * (1 – Math.pow(1 + r, -n)) / r;
} else if (r === 0 && n > 0) {
// Handle zero interest rate case (though unlikely for mortgages)
maxLoanAmount = maxMortgagePayment * n;
}
// The maximum house price is the maximum loan amount plus the down payment
var maxHousePrice = maxLoanAmount + downPayment;
// Ensure results are rounded to sensible currency values
var formattedMaxHousePrice = maxHousePrice.toFixed(2);
var formattedMaxLoanAmount = maxLoanAmount.toFixed(2);
resultDiv.innerHTML = "Your estimated maximum affordable house price is: $" + formattedMaxHousePrice.replace(/\B(?=(\d{3})+(?!\d))/g, ",") + "";
resultDiv.innerHTML += "This is based on an estimated maximum loan amount of: $" + formattedMaxLoanAmount.replace(/\B(?=(\d{3})+(?!\d))/g, ",") + "";
}