Mortgage Affordability Calculator
Use this calculator to estimate how much house you can afford based on your income, debts, and down payment. This is a crucial first step in the home-buying process.
.calculator-container {
font-family: Arial, sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ddd;
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-container p {
text-align: center;
color: #555;
margin-bottom: 30px;
}
.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"] {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
}
.calculator-form button {
width: 100%;
padding: 12px 20px;
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: #f9f9f9;
border: 1px solid #eee;
border-radius: 5px;
text-align: center;
font-size: 18px;
color: #333;
}
.calculator-result strong {
color: #007bff;
}
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
if (isNaN(annualIncome) || isNaN(monthlyDebt) || isNaN(downPayment) || isNaN(interestRate) || isNaN(loanTerm)) {
resultDiv.innerHTML = "Please enter valid numbers for all fields.";
return;
}
// Rule of thumb: Debt-to-Income ratio (DTI) shouldn't exceed 43% for PITI (Principal, Interest, Taxes, Insurance)
// A common lender guideline is a front-end ratio (housing cost only) of around 28% and a back-end ratio (total debt) of around 36%.
// For simplicity, we'll use a combined approach focusing on total debt.
// Let's assume maximum allowable monthly housing payment is 28% of gross monthly income,
// and total monthly debt (including proposed mortgage) should not exceed 36% of gross monthly income.
var grossMonthlyIncome = annualIncome / 12;
var maxTotalMonthlyDebt = grossMonthlyIncome * 0.36; // 36% DTI
var maxMonthlyHousingPayment = grossMonthlyIncome * 0.28; // 28% Front-end ratio
var maxMortgagePaymentAllowable = maxTotalMonthlyDebt – monthlyDebt;
if (maxMortgagePaymentAllowable 0) {
// Formula for Present Value of an Annuity (Loan Amount)
// PV = M * [1 – (1 + r)^-n] / r
// Where PV is the loan amount, M is the monthly payment.
maxLoanAmount = maxMortgagePaymentAllowable * (1 – Math.pow(1 + r, -n)) / r;
} else {
// If interest rate is 0, the loan amount is simply monthly payment * number of months
maxLoanAmount = maxMortgagePaymentAllowable * n;
}
var estimatedAffordability = maxLoanAmount + downPayment;
// Displaying the results
resultDiv.innerHTML = "Estimated Maximum Home Affordability:
$" + estimatedAffordability.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,') + "" +
"Based on an estimated maximum monthly mortgage payment of
$" + maxMortgagePaymentAllowable.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,') + " (Principal & Interest only)." +
"This assumes a
" + (maxMortgagePaymentAllowable / grossMonthlyIncome * 100).toFixed(1) + "% Debt-to-Income ratio.";
}