Mortgage Affordability Calculator
Use this calculator to estimate how much house you can afford based on your income, debts, and desired loan terms. Understanding your borrowing potential is a crucial first step in the home-buying process.
.calculator-container {
font-family: sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #e0e0e0;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.calculator-container h2 {
text-align: center;
margin-bottom: 20px;
color: #333;
}
.calculator-form .form-group {
margin-bottom: 15px;
}
.calculator-form label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
.calculator-form input[type="number"],
.calculator-form input[type="text"] {
width: calc(100% – 12px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
}
.calculator-form button {
width: 100%;
padding: 12px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 18px;
cursor: pointer;
transition: background-color 0.3s ease;
}
.calculator-form button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 25px;
padding: 15px;
background-color: #f8f9fa;
border: 1px solid #e0e0e0;
border-radius: 4px;
text-align: center;
font-size: 18px;
color: #333;
}
.calculator-result p {
margin-bottom: 10px;
}
.calculator-result span {
font-weight: bold;
color: #28a745; /* Green for positive results */
}
.calculator-result .note {
font-size: 14px;
color: #6c757d;
margin-top: 10px;
}
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
// Input validation
if (isNaN(annualIncome) || annualIncome <= 0 ||
isNaN(monthlyDebt) || monthlyDebt < 0 ||
isNaN(downPayment) || downPayment < 0 ||
isNaN(interestRate) || interestRate <= 0 ||
isNaN(loanTerm) || loanTerm <= 0) {
resultDiv.innerHTML = "Please enter valid numbers for all fields.";
return;
}
// Lender Debt-to-Income (DTI) Ratio Guidelines (Commonly used: Front-end 28%, Back-end 36%)
// We'll use a conservative back-end DTI of 36% for this calculator.
var maxDTI = 0.36;
var grossMonthlyIncome = annualIncome / 12;
var maxAllowedMonthlyDebtPayment = grossMonthlyIncome * maxDTI;
var maxAffordableMonthlyMortgage = maxAllowedMonthlyDebtPayment – monthlyDebt;
// Ensure the affordable monthly mortgage is not negative
if (maxAffordableMonthlyMortgage 0 && numberOfPayments > 0) {
var numerator = Math.pow(1 + monthlyInterestRate, numberOfPayments) – 1;
var denominator = monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfPayments);
maxPrincipalLoan = maxAffordableMonthlyMortgage * (numerator / denominator);
} else if (monthlyInterestRate === 0 && numberOfPayments > 0) { // Handle 0% interest rate case
maxPrincipalLoan = maxAffordableMonthlyMortgage * numberOfPayments;
}
var maxHousePrice = maxPrincipalLoan + downPayment;
// Format numbers for display
var formattedMaxHousePrice = maxHousePrice.toLocaleString(undefined, { style: 'currency', currency: 'USD' });
var formattedMaxPrincipalLoan = maxPrincipalLoan.toLocaleString(undefined, { style: 'currency', currency: 'USD' });
var formattedMaxAffordableMonthlyMortgage = maxAffordableMonthlyMortgage.toLocaleString(undefined, { style: 'currency', currency: 'USD' });
resultDiv.innerHTML =
"Based on your inputs, your estimated maximum affordable house price is:
" + formattedMaxHousePrice + "" +
"This includes a down payment of:
" + downPayment.toLocaleString(undefined, { style: 'currency', currency: 'USD' }) + "" +
"Allowing for a maximum principal loan amount of:
" + formattedMaxPrincipalLoan + "" +
"This means you can afford a maximum monthly mortgage payment (principal & interest) of:
" + formattedMaxAffordableMonthlyMortgage + "" +
"Note: This is an estimate. Lender approval depends on many factors including credit score, loan type, property taxes, homeowner's insurance, and specific lender underwriting criteria. Property taxes and insurance are not included in this calculation but will affect your total monthly housing costs.";
}