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 based on your income, existing debts, and current interest rates.
.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 {
color: #555;
line-height: 1.6;
margin-bottom: 20px;
text-align: justify;
}
.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 {
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1rem;
}
button {
display: block;
width: 100%;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
font-size: 1.1rem;
cursor: pointer;
transition: background-color 0.3s ease;
margin-top: 10px;
}
button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 25px;
padding: 15px;
background-color: #e7f3ff;
border: 1px solid #b3d7ff;
border-radius: 5px;
text-align: center;
font-size: 1.1rem;
color: #0056b3;
font-weight: bold;
}
.calculator-result strong {
color: #333;
}
function calculateMortgageAffordability() {
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");
// Basic validation
if (isNaN(annualIncome) || isNaN(monthlyDebt) || isNaN(downPayment) || isNaN(interestRate) || isNaN(loanTerm) ||
annualIncome < 0 || monthlyDebt < 0 || downPayment < 0 || interestRate < 0 || loanTerm <= 0) {
resultDiv.innerHTML = "Error: Please enter valid positive numbers for all fields.";
return;
}
// Lender DTI Ratios (common guidelines, can vary)
// A common guideline is that total housing expenses (PITI) should not exceed 28% of gross monthly income,
// and total debt payments (including PITI) should not exceed 36% of gross monthly income.
var maxHousingRatio = 0.28; // 28% of gross monthly income for PITI
var maxTotalDebtRatio = 0.36; // 36% of gross monthly income for total debt
var monthlyIncome = annualIncome / 12;
// Calculate maximum allowed total monthly debt payments
var maxTotalMonthlyDebt = monthlyIncome * maxTotalDebtRatio;
// Calculate maximum allowed monthly housing payment (PITI)
var maxMonthlyHousingPayment = monthlyIncome * maxHousingRatio;
// Calculate maximum allowed monthly mortgage payment (Principal & Interest only)
// We subtract existing debts from the total allowed debt to find the maximum P&I payment.
// However, lenders often use the 28% rule for housing and 36% for total debt,
// so we'll use the stricter of the two limits for housing.
var maxPrincipalAndInterest = maxMonthlyHousingPayment – (monthlyDebt);
if (maxPrincipalAndInterest 0 && numberOfPayments > 0 && maxPrincipalAndInterest > 0) {
// Formula for Present Value of an Ordinary Annuity: PV = PMT * [1 – (1 + r)^-n] / r
// We are solving for PV (loan amount), where PMT is the maxPrincipalAndInterest payment.
maxLoanAmount = maxPrincipalAndInterest * (1 – Math.pow(1 + monthlyInterestRate, -numberOfPayments)) / monthlyInterestRate;
}
// Total affordable home price is the max loan amount plus the down payment
var affordableHomePrice = maxLoanAmount + downPayment;
// Format results
var formattedAffordableHomePrice = affordableHomePrice.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
var formattedMaxLoanAmount = maxLoanAmount.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
var formattedMaxMonthlyHousingPayment = maxMonthlyHousingPayment.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
resultDiv.innerHTML = "Based on your inputs:" +
"Maximum Estimated Monthly Housing Payment (PITI): " + formattedMaxMonthlyHousingPayment + "" +
"Maximum Affordable Loan Amount: " + formattedMaxLoanAmount + "" +
"Estimated Maximum Affordable Home Price: " + formattedAffordableHomePrice + "" +
"Note: This is an estimate. Actual affordability depends on lender policies, credit score, taxes, insurance, and other fees.";
}