Hbl Salary Loan Calculator

HBL Salary Loan Calculator

function calculateLoan() { const loanAmount = parseFloat(document.getElementById(“loanAmount”).value); const loanTerm = parseFloat(document.getElementById(“loanTerm”).value); const interestRate = parseFloat(document.getElementById(“interestRate”).value); if (isNaN(loanAmount) || isNaN(loanTerm) || isNaN(interestRate) || loanAmount <= 0 || loanTerm <= 0 || interestRate <= 0) { alert("Please enter valid positive values for all fields."); return; } const monthlyRate = interestRate / 100 / 12; const numPayments = loanTerm; const monthlyPayment = (loanAmount * monthlyRate) / (1 – Math.pow(1 + monthlyRate, -numPayments)); const totalPayment = monthlyPayment * numPayments; document.getElementById("monthlyInstallment").value = monthlyPayment.toFixed(2); document.getElementById("totalPayment").value = totalPayment.toFixed(2); } function resetForm() { document.getElementById("hblSalaryLoanCalculator").reset(); document.getElementById("monthlyInstallment").value = ""; document.getElementById("totalPayment").value = ""; }

Leave a Reply

Your email address will not be published. Required fields are marked *