This calculator helps you estimate the maximum mortgage amount you can afford based on your income, debts, and desired loan terms. Understanding your affordability is a crucial first step in the home-buying process.
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 propertyTaxes = parseFloat(document.getElementById("propertyTaxes").value);
var homeInsurance = parseFloat(document.getElementById("homeInsurance").value);
var pmi = parseFloat(document.getElementById("pmi").value);
var resultElement = document.getElementById("result");
resultElement.innerHTML = ""; // Clear previous results
// Input validation
if (isNaN(annualIncome) || annualIncome <= 0 ||
isNaN(monthlyDebt) || monthlyDebt < 0 ||
isNaN(downPayment) || downPayment < 0 ||
isNaN(interestRate) || interestRate <= 0 ||
isNaN(loanTerm) || loanTerm <= 0 ||
isNaN(propertyTaxes) || propertyTaxes < 0 ||
isNaN(homeInsurance) || homeInsurance < 0 ||
isNaN(pmi) || pmi < 0) {
resultElement.innerHTML = "Please enter valid positive numbers for all fields.";
return;
}
// Lender Debt-to-Income (DTI) Ratios – common benchmarks, can vary by lender
var frontEndDTI = 0.28; // Housing expenses (PITI) should be <= 28% of gross monthly income
var backEndDTI = 0.36; // Total debt (PITI + other debts) should be <= 36% of gross monthly income
var grossMonthlyIncome = annualIncome / 12;
// Calculate maximum allowable monthly housing payment (PITI) based on front-end DTI
var maxMonthlyHousingPayment_FE = grossMonthlyIncome * frontEndDTI;
// Calculate maximum allowable total monthly debt payments based on back-end DTI
var maxTotalMonthlyDebt_BE = grossMonthlyIncome * backEndDTI;
// Calculate the maximum monthly payment for PITI based on the stricter of the two DTI limits
var maxMonthlyPITI = Math.min(maxMonthlyHousingPayment_FE, maxTotalMonthlyDebt_BE – monthlyDebt);
if (maxMonthlyPITI < 0) {
resultElement.innerHTML = "Based on your debts and income, you may not qualify for a mortgage at this time. Please consult with a mortgage lender for personalized advice.";
return;
}
// Components of PITI (Principal, Interest, Taxes, Insurance)
var monthlyPropertyTaxes = propertyTaxes / 12;
var monthlyHomeInsurance = homeInsurance / 12;
var monthlyPMI = pmi / 12;
var monthlyTotalInsuranceAndTaxes = monthlyPropertyTaxes + monthlyHomeInsurance + monthlyPMI;
// Calculate the maximum allowable monthly principal and interest payment
var maxMonthlyPrincipalInterest = maxMonthlyPITI – monthlyTotalInsuranceAndTaxes;
if (maxMonthlyPrincipalInterest 0 && numberOfPayments > 0) {
var factor = Math.pow(1 + monthlyInterestRate, numberOfPayments);
maxLoanAmount = maxMonthlyPrincipalInterest * (factor – 1) / (monthlyInterestRate * factor);
} else if (maxMonthlyPrincipalInterest > 0) { // Handle 0% interest rate scenario
maxLoanAmount = maxMonthlyPrincipalInterest * numberOfPayments;
}
var estimatedMaxHomePrice = maxLoanAmount + downPayment;
resultElement.innerHTML = `
Estimated Mortgage Affordability
Maximum Loan Amount You May Qualify For: $${maxLoanAmount.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')}
Estimated Maximum Home Price (Loan + Down Payment): $${estimatedMaxHomePrice.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')}
Estimated Maximum Monthly PITI Payment: $${maxMonthlyPITI.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')}
Note: This is an estimate. Actual loan approval and amounts depend on lender's specific underwriting criteria, credit score, employment history, and other factors.
`;
}
.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;
margin-bottom: 15px;
color: #333;
}
.calculator-container p {
color: #555;
line-height: 1.6;
}
.calculator-inputs {
display: grid;
grid-template-columns: 1fr 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 #ccc;
border-radius: 4px;
font-size: 1rem;
}
button {
display: block;
width: 100%;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 1.1rem;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
#result {
margin-top: 25px;
padding: 15px;
background-color: #e9ecef;
border: 1px solid #ced4da;
border-radius: 4px;
text-align: center;
}
#result h3 {
margin-top: 0;
color: #333;
}
#result p {
margin-bottom: 10px;
}