Results
Interest Rate Differential: ${diffPercent}
Differential Amount: ${diffAmountText}
Generated on: ${new Date().toLocaleDateString()} ${new Date().toLocaleTimeString()}
`;
const printWindow = window.open('', '_blank');
if (printWindow) {
printWindow.document.write('
Interest Rate Differentials Report');
printWindow.document.write(pdfContent);
printWindow.document.write('');
printWindow.document.close(); // Necessary for IE >= 10
printWindow.focus(); // Necessary for IE >= 10
// Timeout to ensure content is loaded before printing
setTimeout(() => {
printWindow.print();
// printWindow.close(); // Optional: close window after print dialog
}, 250);
} else {
alert('Could not open print window. Please check your browser pop-up settings.');
}
});
// Helper function to clear input errors on focus
function clearErrorOnFocus(inputElement, errorElement) {
if (inputElement && errorElement) {
inputElement.addEventListener('focus', function() {
errorElement.textContent = '';
});
}
}
clearErrorOnFocus(item1RateInput, item1RateError);
clearErrorOnFocus(item2RateInput, item2RateError);
clearErrorOnFocus(principalAmountInput, principalAmountError);
});