Mortgage Affordability Calculator
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 payment by considering your income, existing debts, and the estimated interest rate and loan term.
function calculateMortgageAffordability() {
var annualIncome = parseFloat(document.getElementById("annualIncome").value);
var monthlyDebtPayments = parseFloat(document.getElementById("monthlyDebtPayments").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
if (isNaN(annualIncome) || isNaN(monthlyDebtPayments) || isNaN(downPayment) || isNaN(interestRate) || isNaN(loanTermYears) ||
annualIncome < 0 || monthlyDebtPayments < 0 || downPayment < 0 || interestRate < 0 || loanTermYears <= 0) {
resultDiv.innerHTML = "Please enter valid positive numbers for all fields. Loan term must be greater than 0.";
return;
}
// General guideline: A common DTI ratio is 28% for housing costs and 36% for total debt.
// We'll use the 28% for housing costs as a basis for affordability.
var maxMonthlyHousingPayment = annualIncome * 0.28 / 12;
// Calculate the maximum allowable total monthly debt payments based on the 36% DTI.
var maxTotalMonthlyDebt = annualIncome * 0.36 / 12;
// The actual maximum monthly debt payment we can afford for the mortgage
// is what's left after subtracting existing debts from the total allowed debt.
var maxMortgagePayment = maxTotalMonthlyDebt – monthlyDebtPayments;
// Ensure the calculated max mortgage payment isn't negative
if (maxMortgagePayment 0) {
// M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1] (This is the formula for monthly payment)
// We need to solve for P (Principal Loan Amount)
// P = M [ (1 + i)^n – 1] / [ i(1 + i)^n ]
maxLoanAmount = affordableMonthlyPayment * Math.pow(1 + monthlyInterestRate, numberOfPayments) – affordableMonthlyPayment;
maxLoanAmount = maxLoanAmount / (monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfPayments));
} else { // Handle 0% interest rate
maxLoanAmount = affordableMonthlyPayment * numberOfPayments;
}
var maxAffordableHomePrice = maxLoanAmount + downPayment;
resultDiv.innerHTML =
"
Your Estimated Affordability:
" +
"
Maximum Monthly Mortgage Payment (Principal & Interest): $" + affordableMonthlyPayment.toFixed(2) + "" +
"
Estimated Maximum Loan Amount: $" + maxLoanAmount.toFixed(2) + "" +
"
Estimated Maximum Affordable Home Price (including down payment): $" + maxAffordableHomePrice.toFixed(2) + "" +
"
Note: This calculator provides an estimate based on common debt-to-income ratios (28% for housing, 36% total). It does not include property taxes, homeowners insurance, HOA fees, or private mortgage insurance (PMI), which will increase your actual monthly payment.";
}
.calculator-container {
font-family: Arial, sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
background-color: #f9f9f9;
}
.calculator-container h2 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
.calculator-inputs {
display: grid;
grid-template-columns: 1fr;
gap: 15px;
}
.input-group {
display: flex;
flex-direction: column;
}
.input-group label {
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
.input-group input {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
}
.calculator-container button {
grid-column: 1 / -1;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 18px;
cursor: pointer;
transition: background-color 0.3s ease;
}
.calculator-container button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 25px;
padding: 15px;
border: 1px solid #e0e0e0;
border-radius: 4px;
background-color: #fff;
text-align: center;
}
.calculator-result h3 {
color: #007bff;
margin-bottom: 15px;
}
.calculator-result p {
margin-bottom: 10px;
font-size: 16px;
line-height: 1.5;
}
.calculator-result strong {
color: #333;
}
.calculator-result small {
color: #777;
font-size: 0.85em;
}