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 potential mortgage amount based on your income, debts, and a few key lending assumptions. It's important to remember that this is an estimate, and your actual approved loan amount may vary based on lender-specific criteria, credit score, down payment, and market conditions.
function calculateMortgageAffordability() {
var grossAnnualIncome = parseFloat(document.getElementById("grossAnnualIncome").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 resultElement = document.getElementById("result");
resultElement.innerHTML = ""; // Clear previous results
if (isNaN(grossAnnualIncome) || isNaN(monthlyDebtPayments) || isNaN(downPayment) || isNaN(interestRate) || isNaN(loanTermYears)) {
resultElement.innerHTML = "Please enter valid numbers for all fields.";
return;
}
if (grossAnnualIncome <= 0 || monthlyDebtPayments < 0 || downPayment < 0 || interestRate <= 0 || loanTermYears <= 0) {
resultElement.innerHTML = "Please enter positive values for income, interest rate, and loan term, and non-negative values for debt and down payment.";
return;
}
// Typical Debt-to-Income (DTI) ratios lenders might consider
// Front-end DTI (housing costs including PITI) typically around 28-31%
// Back-end DTI (total debt including housing) typically around 36-43%
// We'll use a common guideline of 36% for total monthly debt payments (including proposed mortgage)
var maxTotalMonthlyPaymentRatio = 0.36;
var monthlyGrossIncome = grossAnnualIncome / 12;
var maxAllowedTotalMonthlyDebt = monthlyGrossIncome * maxTotalMonthlyPaymentRatio;
var maxAffordableMonthlyMortgagePayment = maxAllowedTotalMonthlyDebt – monthlyDebtPayments;
if (maxAffordableMonthlyMortgagePayment <= 0) {
resultElement.innerHTML = "Based on your current debt and income, you may not qualify for an additional mortgage payment at this time. Consider reducing debt or increasing income.";
return;
}
// Mortgage payment formula: M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1]
// Where:
// M = Monthly Payment
// P = Principal Loan Amount
// i = Monthly Interest Rate
// n = Total Number of Payments (loan term in months)
var monthlyInterestRate = (interestRate / 100) / 12;
var numberOfPayments = loanTermYears * 12;
// We need to solve for P (Principal Loan Amount)
// P = M * [ (1 + i)^n – 1] / [ i(1 + i)^n ]
var maxLoanAmount = maxAffordableMonthlyMortgagePayment * (Math.pow(1 + monthlyInterestRate, numberOfPayments) – 1) / (monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfPayments));
var maxHomePrice = maxLoanAmount + downPayment;
resultElement.innerHTML = "
Your Estimated Mortgage Affordability
" +
"
Estimated Maximum Home Price: $" + maxHomePrice.toFixed(2) + "" +
"
Estimated Maximum Loan Amount: $" + maxLoanAmount.toFixed(2) + "" +
"
Estimated Maximum Monthly Mortgage Payment (P&I): $" + maxAffordableMonthlyMortgagePayment.toFixed(2) + "" +
"
Note: This estimate excludes property taxes, homeowner's insurance (PITI), HOA fees, and potential PMI. Your actual affordability may differ.";
}
.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-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% – 22px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
}
.calculator-form button {
width: 100%;
padding: 12px 18px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
.calculator-form button:hover {
background-color: #45a049;
}
.calculator-result {
margin-top: 25px;
padding: 15px;
background-color: #eef7ee;
border: 1px solid #d8e8d8;
border-radius: 4px;
}
.calculator-result h3 {
margin-top: 0;
color: #336633;
}
.calculator-result p {
margin-bottom: 10px;
color: #444;
}
.calculator-result strong {
color: #333;
}
.calculator-result small {
color: #777;
font-style: italic;
}