Mortgage Affordability Calculator
This calculator helps you estimate how much you can afford to borrow for a mortgage. It considers your income, existing debts, and desired loan term.
.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;
margin-bottom: 15px;
color: #333;
}
.calculator-container p {
text-align: center;
color: #555;
margin-bottom: 25px;
line-height: 1.6;
}
.calculator-form .form-group {
margin-bottom: 15px;
display: flex;
flex-direction: column;
}
.calculator-form label {
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.calculator-form input[type="number"],
.calculator-form input[type="text"] {
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1rem;
}
.calculator-form button {
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 1.1rem;
cursor: pointer;
transition: background-color 0.3s ease;
}
.calculator-form button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 25px;
padding: 15px;
background-color: #e9ecef;
border: 1px solid #ced4da;
border-radius: 4px;
text-align: center;
font-size: 1.2rem;
color: #333;
min-height: 50px;
display: flex;
align-items: center;
justify-content: center;
}
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 resultElement = document.getElementById("result");
if (isNaN(annualIncome) || isNaN(monthlyDebt) || isNaN(downPayment) || isNaN(interestRate) || isNaN(loanTerm) ||
annualIncome < 0 || monthlyDebt < 0 || downPayment < 0 || interestRate < 0 || loanTerm <= 0) {
resultElement.innerHTML = "Please enter valid positive numbers for all fields.";
return;
}
// Rule of thumb: Lenders often use a debt-to-income ratio (DTI).
// A common guideline is that total housing expenses (PITI – Principal, Interest, Taxes, Insurance)
// should not exceed 28% of gross monthly income, and total debt payments (including PITI)
// should not exceed 36% of gross monthly income. We'll aim for the 36% total debt limit for affordability.
var grossMonthlyIncome = annualIncome / 12;
var maxTotalMonthlyDebtAllowed = grossMonthlyIncome * 0.36; // 36% DTI for total debt
var maxMortgagePaymentAllowed = maxTotalMonthlyDebtAllowed – monthlyDebt;
if (maxMortgagePaymentAllowed 0) {
var numerator = Math.pow(1 + monthlyInterestRate, numberOfPayments) – 1;
var denominator = monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfPayments);
maxLoanAmount = maxMortgagePaymentAllowed * (numerator / denominator);
} else { // Handle case of 0% interest rate
maxLoanAmount = maxMortgagePaymentAllowed * numberOfPayments;
}
// The total home price you can afford is the max loan amount plus your down payment.
var affordableHomePrice = maxLoanAmount + downPayment;
resultElement.innerHTML = "Estimated Maximum Affordable Home Price:
$" + affordableHomePrice.toFixed(0).replace(/\B(?=(\d{3})+(?!\d))/g, ",") + "";
resultElement.innerHTML += "
(This estimate assumes your total monthly debt payments, including mortgage P&I, do not exceed 36% of your gross monthly income. It does not include property taxes, homeowner's insurance, or PMI, which will increase your actual monthly housing cost.)";
}