Mortgage Affordability Calculator
This calculator helps you estimate how much house you can afford based on your income, debts, and desired monthly payment. It's a crucial first step in the home-buying process, allowing you to set realistic expectations and focus your search on suitable properties.
.calculator-container {
font-family: sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
background-color: #f9f9f9;
}
.calculator-container h2 {
text-align: center;
color: #333;
margin-bottom: 15px;
}
.calculator-container p {
text-align: justify;
color: #555;
line-height: 1.6;
margin-bottom: 25px;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.form-group input[type="number"] {
width: calc(100% – 12px);
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
button {
display: block;
width: 100%;
padding: 10px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 20px;
padding: 15px;
background-color: #e9ecef;
border: 1px solid #ced4da;
border-radius: 5px;
text-align: center;
font-size: 1.1em;
color: #333;
}
.calculator-result strong {
color: #007bff;
}
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 maxPayment = parseFloat(document.getElementById("maxPayment").value);
var resultDiv = document.getElementById("result");
if (isNaN(annualIncome) || isNaN(monthlyDebt) || isNaN(downPayment) || isNaN(interestRate) || isNaN(loanTerm) || isNaN(maxPayment)) {
resultDiv.innerHTML = "Please enter valid numbers for all fields.";
return;
}
// Rule of thumb: Housing expenses (principal, interest, taxes, insurance) should not exceed 28% of gross monthly income.
var maxHousingExpenseRatio = 0.28;
// Rule of thumb: Total debt payments (housing + other debts) should not exceed 36% of gross monthly income.
var maxTotalDebtRatio = 0.36;
var grossMonthlyIncome = annualIncome / 12;
// Calculate maximum affordable monthly PITI (Principal, Interest, Taxes, Insurance) based on income ratio
var maxAffordablePITIByIncomeRatio = grossMonthlyIncome * maxHousingExpenseRatio;
// Calculate maximum affordable total monthly debt based on income ratio
var maxAffordableTotalDebtByIncomeRatio = grossMonthlyIncome * maxTotalDebtRatio;
// Calculate maximum affordable monthly PITI based on total debt ratio, considering existing debts
var maxAffordablePITIByDebtRatio = maxAffordableTotalDebtByIncomeRatio – monthlyDebt;
// The actual maximum PITI is the lower of the two affordability measures
var actualMaxPITI = Math.min(maxAffordablePITIByIncomeRatio, maxAffordablePITIByDebtRatio);
// If the user's desired max payment is lower than what's affordable, use the user's max payment
var effectiveMaxPITI = Math.min(actualMaxPITI, maxPayment);
if (effectiveMaxPITI 0 && numberOfPayments > 0) {
maximumLoanAmount = effectiveMaxPITI * (Math.pow(1 + monthlyInterestRate, numberOfPayments) – 1) / (monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfPayments));
} else if (monthlyInterestRate === 0) {
// Handle zero interest rate (though rare for mortgages)
maximumLoanAmount = effectiveMaxPITI * numberOfPayments;
}
var estimatedMaxHomePrice = maximumLoanAmount + downPayment;
var formattedMaxHomePrice = estimatedMaxHomePrice.toLocaleString(undefined, { style: 'currency', currency: 'USD' });
var formattedMaxLoanAmount = maximumLoanAmount.toLocaleString(undefined, { style: 'currency', currency: 'USD' });
var formattedEffectiveMaxPITI = effectiveMaxPITI.toLocaleString(undefined, { style: 'currency', currency: 'USD' });
resultDiv.innerHTML = "Your estimated maximum affordable home price is:
" + formattedMaxHomePrice + "." +
"This is based on a maximum loan amount of:
" + formattedMaxLoanAmount + "." +
"Your estimated maximum affordable monthly housing payment (PITI) is:
" + formattedEffectiveMaxPITI + ".";
}