This calculator helps you estimate how much house you can afford based on your income, debts, and desired down payment. It's a crucial tool for understanding your budget before you start house hunting.
.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;
color: #333;
margin-bottom: 15px;
}
.calculator-container p {
text-align: justify;
color: #555;
margin-bottom: 25px;
line-height: 1.6;
}
.calculator-inputs {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 15px;
margin-bottom: 20px;
}
.input-group {
display: flex;
flex-direction: column;
}
.input-group label {
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.input-group input {
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1rem;
}
button {
display: block;
width: 100%;
padding: 12px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
font-size: 1.1rem;
cursor: pointer;
transition: background-color 0.3s ease;
margin-top: 10px;
}
button:hover {
background-color: #45a049;
}
.calculator-result {
margin-top: 25px;
padding: 15px;
border: 1px dashed #4CAF50;
border-radius: 5px;
background-color: #e8f5e9;
text-align: center;
font-size: 1.2rem;
color: #333;
font-weight: bold;
}
function calculateMortgageAffordability() {
var grossMonthlyIncome = parseFloat(document.getElementById("grossMonthlyIncome").value);
var existingMonthlyDebt = parseFloat(document.getElementById("existingMonthlyDebt").value);
var downPayment = parseFloat(document.getElementById("downPayment").value);
var estimatedAnnualPropertyTax = parseFloat(document.getElementById("estimatedAnnualPropertyTax").value);
var estimatedAnnualHomeInsurance = parseFloat(document.getElementById("estimatedAnnualHomeInsurance").value);
var interestRate = parseFloat(document.getElementById("interestRate").value);
var loanTermYears = parseFloat(document.getElementById("loanTermYears").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
// Basic validation
if (isNaN(grossMonthlyIncome) || isNaN(existingMonthlyDebt) || isNaN(downPayment) ||
isNaN(estimatedAnnualPropertyTax) || isNaN(estimatedAnnualHomeInsurance) ||
isNaN(interestRate) || isNaN(loanTermYears) ||
grossMonthlyIncome <= 0 || existingMonthlyDebt < 0 || downPayment < 0 ||
estimatedAnnualPropertyTax < 0 || estimatedAnnualHomeInsurance < 0 ||
interestRate <= 0 || loanTermYears <= 0) {
resultDiv.innerHTML = "Please enter valid positive numbers for all fields. Existing monthly debt can be zero.";
return;
}
// Lender Debt-to-Income (DTI) Ratio guidelines – typically 28% for PITI and 36% for total debt
// PITI = Principal, Interest, Taxes, Insurance
var maxMonthlyPITI = grossMonthlyIncome * 0.28;
var maxTotalMonthlyPayment = grossMonthlyIncome * 0.36;
var maxAllowedMortgagePayment = maxTotalMonthlyPayment – existingMonthlyDebt;
if (maxAllowedMortgagePayment <= 0) {
resultDiv.innerHTML = "Based on your income and existing debt, you may not qualify for a mortgage.";
return;
}
// Calculate estimated monthly taxes and insurance
var monthlyTaxes = estimatedAnnualPropertyTax / 12;
var monthlyInsurance = estimatedAnnualHomeInsurance / 12;
var monthlyPITI_excluding_principal_interest = monthlyTaxes + monthlyInsurance;
// Calculate the maximum P&I payment you can afford
var maxPrincipalInterestPayment = Math.min(maxMonthlyPITI, maxAllowedMortgagePayment) – monthlyPITI_excluding_principal_interest;
if (maxPrincipalInterestPayment 0) {
maxLoanAmount = maxPrincipalInterestPayment * (1 – Math.pow(1 + monthlyInterestRate, -numberOfMonths)) / monthlyInterestRate;
} else {
// Handle zero interest rate scenario (less common for mortgages, but for completeness)
maxLoanAmount = maxPrincipalInterestPayment * numberOfMonths;
}
var estimatedMaxHomePrice = maxLoanAmount + downPayment;
resultDiv.innerHTML = "Estimated Maximum Home Price: $" + estimatedMaxHomePrice.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",") + "";
resultDiv.innerHTML += "This is an estimate. Actual affordability depends on lender approval, credit score, and other factors.";
}