function calculateDTI() {
// 1. Get input values and handle empty/invalid inputs by defaulting to 0
var incomeStr = document.getElementById('dti-gross-income').value;
var income = parseFloat(incomeStr) || 0;
var mortgageStr = document.getElementById('dti-mortgage-rent').value;
var mortgage = parseFloat(mortgageStr) || 0;
var autoStr = document.getElementById('dti-auto-loans').value;
var auto = parseFloat(autoStr) || 0;
var studentStr = document.getElementById('dti-student-loans').value;
var student = parseFloat(studentStr) || 0;
var cardsStr = document.getElementById('dti-credit-cards').value;
var cards = parseFloat(cardsStr) || 0;
var otherStr = document.getElementById('dti-other-debt').value;
var other = parseFloat(otherStr) || 0;
// Get result display elements
var resultDiv = document.getElementById('dti-result');
var resultText = document.getElementById('dti-result-text');
var statusText = document.getElementById('dti-status-text');
// 2. Validate Income (Prevent division by zero or negative income)
if (income <= 0 || isNaN(income)) {
resultDiv.style.display = "block";
resultDiv.style.backgroundColor = "#f8d7da"; // Red error color
resultDiv.style.color = "#721c24";
resultText.innerHTML = "Error";
statusText.innerHTML = "Please enter a valid Monthly Gross Income greater than zero.";
return;
}
// 3. Calculate Total Monthly Debt
var totalDebt = mortgage + auto + student + cards + other;
// 4. Calculate DTI Ratio Percentage
// Formula: (Total Monthly Debt / Gross Monthly Income) * 100
var dtiRatio = (totalDebt / income) * 100;
// 5. Determine Status Message and Color based on standard lending guidelines
var statusMessage = "";
var resultingBackgroundColor = "";
var resultingTextColor = "#333";
if (dtiRatio = 36 && dtiRatio <= 43) {
statusMessage = "Acceptable. You are within typical limits for most mortgages, though some lenders may require compensating factors.";
resultingBackgroundColor = "#fff3cd"; // Yellow/Orange
resultingTextColor = "#856404";
} else {
statusMessage = "High Risk. A DTI above 43% significantly reduces your ability to qualify for new credit or mortgages under standard guidelines.";
resultingBackgroundColor = "#f8d7da"; // Red
resultingTextColor = "#721c24";
}
// 6. Display Results
resultDiv.style.display = "block";
resultDiv.style.backgroundColor = resultingBackgroundColor;
resultDiv.style.color = resultingTextColor;
// Format to one decimal place
resultText.innerHTML = dtiRatio.toFixed(1) + "% DTI Ratio";
statusText.innerHTML = "Your total monthly debt obligations are $" + totalDebt.toFixed(2) + ". " + statusMessage;
}
Understanding Your Debt-to-Income (DTI) Ratio
Your Debt-to-Income (DTI) ratio is a critical percentage that lenders use to evaluate your financial health and ability to repay borrowed money. It compares how much you owe each month to how much you earn before taxes.
Why DTI Matters
When you apply for a mortgage, car loan, or personal line of credit, the lender wants to know if you can afford to take on new debt. A lower DTI indicates that you have a good balance between debt and income. Conversely, a high DTI signals to lenders that you might be overextended financially, increasing the risk that you might default on a loan.
While credit scores measure your history of repaying debt, DTI measures your current capacity to manage payments.
How DTI is Calculated
The standard "back-end" DTI formula used by most mortgage lenders includes all your minimum monthly debt payments divided by your gross monthly income.
Gross Monthly Income: Your total income before taxes and other deductions.
Total Monthly Debt: This includes housing costs (rent or mortgage principal, interest, taxes, insurance), minimum credit card payments, auto loans, student loans, and any other fixed monthly debts. It generally does NOT include variable expenses like groceries, utilities, or gas.
A Realistic Example
Let's imagine Jane earns a gross salary of $6,000 per month. Her debts are:
Mortgage payment: $1,800
Car loan: $400
Student loans: $300
Credit card minimums: $150
Her total monthly debt is $1,800 + $400 + $300 + $150 = $2,650.
To find her DTI, we calculate: ($2,650 / $6,000) * 100 = 44.2%.
In this scenario, Jane's DTI is slightly above the typical 43% threshold used for many Qualified Mortgages, meaning she might face higher interest rates or need to reduce her debt before qualifying easily.
Interpreting Your Results
35% or less: Generally considered excellent. You likely have disposable income and are viewed as a low-risk borrower.
36% to 43%: This is the typical range for mortgage approval. While acceptable, lenders may scrutinize your application more closely as you approach the higher end.
44% or higher: Considered high risk. Many lenders will deny mortgage applications with a DTI in this range because it suggests you may struggle to handle additional monthly payments.