Understanding how much you can afford to borrow for a mortgage is a crucial first step in the home-buying process. This calculator helps you estimate your maximum mortgage amount based on your income, existing debts, and down payment. Remember, this is an estimate, and your actual borrowing capacity will be determined by lenders after a thorough review of your financial situation.
function calculateMortgageAffordability() {
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;
}
// Lender typically uses Debt-to-Income (DTI) ratios. Common thresholds are 28% for housing and 36% for total debt.
// We'll use a simplified approach focusing on what lenders might allow for total monthly payments.
// A common guideline is that total housing costs (PITI: Principal, Interest, Taxes, Insurance) shouldn't exceed 28% of gross monthly income,
// and total debt (housing + other debts) shouldn't exceed 36% of gross monthly income.
var grossMonthlyIncome = annualIncome / 12;
// Maximum housing payment based on 28% DTI (Principal, Interest, Taxes, Insurance)
var maxHousingPayment = grossMonthlyIncome * 0.28;
// Maximum total debt payment based on 36% DTI
var maxTotalDebtPayment = grossMonthlyIncome * 0.36;
// Maximum allowable monthly mortgage payment (excluding taxes, insurance, etc. for simplicity in this calculator's core affordability estimate)
// We'll focus on the principal and interest portion here. Lenders will factor in PITI.
// For simplicity, let's assume taxes and insurance add 1.2% of the home value annually, so about 0.1% of home value per month.
// A more direct way is to see how much loan P&I we can afford given the total debt constraint.
var allowableMortgagePIMax = maxTotalDebtPayment – monthlyDebt;
if (allowableMortgagePIMax 0 && numberOfPayments > 0) {
maximumLoanAmount = allowableMortgagePIMax * (Math.pow(1 + monthlyInterestRate, numberOfPayments) – 1) / (monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfPayments));
} else if (monthlyInterestRate === 0) {
// Handle 0 interest rate case (unlikely but possible)
maximumLoanAmount = allowableMortgagePIMax * numberOfPayments;
}
// The maximum home price is the maximum loan amount plus the down payment.
var maxHomePrice = maximumLoanAmount + downPayment;
// Round values for display
var formattedMaximumLoan = maximumLoanAmount.toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 0 });
var formattedMaxHomePrice = maxHomePrice.toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 0 });
var formattedAllowablePIMax = allowableMortgagePIMax.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
resultDiv.innerHTML = `
Your Estimated Affordability:
Estimated Maximum Loan Amount: $${formattedMaximumLoan}
Estimated Maximum Home Price (with your down payment): $${formattedMaxHomePrice}
This estimate assumes your total monthly housing payment (Principal, Interest, Taxes, Insurance) is within approximately 28% of your gross monthly income and your total debt (including estimated housing) is within 36% of your gross monthly income. The calculated 'Maximum Loan Amount' is based on the principal and interest portion of your payment, allowing for your other debts. Lenders will consider many factors, including your credit score, loan type, and specific property taxes and insurance costs.
`;
}
.calculator-container {
font-family: Arial, sans-serif;
border: 1px solid #ccc;
padding: 20px;
border-radius: 8px;
max-width: 600px;
margin: 20px auto;
background-color: #f9f9f9;
}
.calculator-container h2 {
text-align: center;
margin-bottom: 20px;
color: #333;
}
.calculator-inputs {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin-bottom: 20px;
}
.form-group {
display: flex;
flex-direction: column;
}
.form-group label {
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
.form-group input[type="number"] {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1em;
box-sizing: border-box; /* Important for consistent sizing */
}
.calculator-container button {
background-color: #4CAF50;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 1.1em;
width: 100%;
transition: background-color 0.3s ease;
}
.calculator-container button:hover {
background-color: #45a049;
}
.calculator-result {
margin-top: 25px;
padding: 15px;
border: 1px solid #e0e0e0;
background-color: #fff;
border-radius: 4px;
text-align: center;
}
.calculator-result h3 {
margin-top: 0;
color: #333;
}
.calculator-result p {
margin-bottom: 10px;
color: #444;
font-size: 1.1em;
}
.calculator-result small {
font-size: 0.85em;
color: #777;
display: block; /* Ensure it's on its own line */
margin-top: 10px;
}