Mortgage Affordability Calculator
Use this calculator to estimate how much house you can afford based on your income, debts, and desired mortgage terms. Understanding your potential borrowing power is a crucial first step in the home-buying process.
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;
}
if (annualIncome <= 0 || monthlyDebt < 0 || downPayment < 0 || interestRate <= 0 || loanTerm <= 0) {
resultDiv.innerHTML = "Please enter positive values for income, interest rate, and loan term. Debt and down payment cannot be negative.";
return;
}
// General guideline: Debt-to-income ratio (DTI) should ideally be below 36%, but lenders may allow up to 43% or more.
// We'll use a common guideline of 36% for total debt including PITI (Principal, Interest, Taxes, Insurance).
var maxTotalMonthlyPayment = annualIncome / 12 * 0.36;
var maxMortgagePayment = maxTotalMonthlyPayment – monthlyDebt;
if (maxMortgagePayment 0) {
maxLoanAmount = maxMortgagePayment * (1 – Math.pow(1 + monthlyInterestRate, -numberOfPayments)) / monthlyInterestRate;
} else {
// Handle 0% interest rate case (though rare for mortgages)
maxLoanAmount = maxMortgagePayment * numberOfPayments;
}
// Estimate property taxes and homeowner's insurance (these are approximations and vary widely)
// A common estimate is 1% of the property value annually for taxes and 0.5% for insurance.
// Since we are calculating affordability, we'll assume these costs are a percentage of the loan amount for estimation.
// This is a simplification; actual PITI calculations are more complex.
var estimatedAnnualTaxesAndInsurance = (downPayment + maxLoanAmount) * 0.015; // 1.5% of total home value
var estimatedMonthlyTaxesAndInsurance = estimatedAnnualTaxesAndInsurance / 12;
// Recalculate maxMortgagePayment considering taxes and insurance
maxMortgagePayment = maxMortgagePayment – estimatedMonthlyTaxesAndInsurance;
if (maxMortgagePayment 0) {
maxLoanAmount = maxMortgagePayment * (1 – Math.pow(1 + monthlyInterestRate, -numberOfPayments)) / monthlyInterestRate;
} else {
maxLoanAmount = maxMortgagePayment * numberOfPayments;
}
var maxHomeAffordability = maxLoanAmount + downPayment;
resultDiv.innerHTML =
"
Estimated Maximum Mortgage Amount: $" + maxLoanAmount.toFixed(2) + "" +
"
Estimated Maximum Home Price You Can Afford: $" + maxHomeAffordability.toFixed(2) + "" +
"
Disclaimer: This is an estimate based on general guidelines (like a 36% DTI ratio). Actual loan approval depends on lender policies, credit score, loan type, and other factors. Property taxes and insurance are estimates. Consult with a mortgage professional for precise figures.";
}
.calculator-container {
font-family: sans-serif;
border: 1px solid #ddd;
padding: 20px;
border-radius: 8px;
max-width: 500px;
margin: 20px auto;
background-color: #f9f9f9;
}
.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"] {
width: calc(100% – 22px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
.calculator-form button {
width: 100%;
padding: 10px 15px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s ease;
}
.calculator-form button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 20px;
padding: 15px;
background-color: #e9ecef;
border: 1px solid #ced4da;
border-radius: 4px;
}
.calculator-result p {
margin-bottom: 10px;
color: #333;
font-size: 1.1em;
}
.calculator-result strong {
color: #0056b3;
}
.calculator-result em {
font-size: 0.9em;
color: #666;
display: block;
margin-top: 10px;
}