Understanding how much house you can afford is a crucial first step in the home-buying process. This Mortgage Affordability Calculator helps you estimate your maximum loan amount based on your income, debts, and estimated interest rate. Remember, this is an estimate, and lenders will consider many other factors.
function calculateAffordability() {
var grossMonthlyIncome = parseFloat(document.getElementById("grossMonthlyIncome").value);
var monthlyDebtPayments = parseFloat(document.getElementById("monthlyDebtPayments").value);
var downPayment = parseFloat(document.getElementById("downPayment").value);
var interestRate = parseFloat(document.getElementById("interestRate").value);
var loanTermYears = parseInt(document.getElementById("loanTermYears").value);
var maxDTI = 0.43; // Maximum Debt-to-Income ratio (common guideline)
var resultDiv = document.getElementById("result");
if (isNaN(grossMonthlyIncome) || isNaN(monthlyDebtPayments) || isNaN(downPayment) || isNaN(interestRate) || isNaN(loanTermYears) ||
grossMonthlyIncome < 0 || monthlyDebtPayments < 0 || downPayment < 0 || interestRate < 0 || loanTermYears <= 0) {
resultDiv.innerHTML = "Please enter valid positive numbers for all fields.";
return;
}
// Calculate maximum housing payment allowed based on DTI
var maxHousingPayment = (grossMonthlyIncome * maxDTI) – monthlyDebtPayments;
if (maxHousingPayment 0) {
// Standard mortgage payment formula: M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1]
// We need to solve for P (Principal Loan Amount)
// P = M [ (1 + i)^n – 1] / [ i(1 + i)^n ]
maxLoanAmount = maxHousingPayment * (Math.pow(1 + monthlyInterestRate, numberOfPayments) – 1) / (monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfPayments));
} else {
// If interest rate is 0% (rare for mortgages, but for calculation completeness)
maxLoanAmount = maxHousingPayment * numberOfPayments;
}
var estimatedMaxHomePrice = maxLoanAmount + downPayment;
resultDiv.innerHTML = "
Estimated Affordability
" +
"Maximum Housing Payment You Can Afford (P&I): $" + maxHousingPayment.toFixed(2) + "" +
"Estimated Maximum Loan Amount: $" + maxLoanAmount.toFixed(2) + "" +
"Estimated Maximum Home Price (including down payment): $" + estimatedMaxHomePrice.toFixed(2) + "" +
"Note: This is an estimate. It does not include property taxes, homeowners insurance, HOA fees (often called PITI – Principal, Interest, Taxes, Insurance), or lender fees. It also doesn't account for your credit score or lender-specific underwriting criteria. Consult with a mortgage professional for a pre-approval.";
}
.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;
margin-bottom: 20px;
color: #333;
}
.calculator-container p {
line-height: 1.6;
color: #555;
}
.calculator-inputs {
display: grid;
grid-template-columns: 1fr 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;
}
.calculator-container button {
background-color: #4CAF50;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
display: block;
width: 100%;
margin-top: 15px;
}
.calculator-container button:hover {
background-color: #45a049;
}
.calculator-result {
margin-top: 25px;
padding: 15px;
border: 1px dashed #ddd;
background-color: #fff;
border-radius: 4px;
}
.calculator-result h3 {
color: #333;
margin-bottom: 10px;
}
.calculator-result p {
margin-bottom: 8px;
color: #333;
}
.calculator-result strong {
color: #007bff;
}