Revise your toggle code to clearly include or exclude classes according to the existing state:
document.querySelectorAll('.toggle-password').forEach(icon => {
icon.addEventListener('click', () => {
const targetId = icon.getAttribute('data-target');
const input = document.getElementById(targetId);
if (!input) return;
const isHidden = input.type === 'password';
input.type = isHidden ? 'text' : 'password';
// Update icon classes explicitly
if (isHidden) {
// Show as slashed eye
icon.classList.remove('fa-eye');
icon.classList.add('fa-eye-slash');
} else {
// Show as eye
icon.classList.remove('fa-eye-slash');
icon.classList.add('fa-eye');
}
});
});