Quick one: event handling bug here.
const button = document.querySelector('#save');
button.addEventListener('click', saveForm());
function saveForm() {
console.log('saved');
}
Reply with what is broken and how you would fix it.
Quick one: event handling bug here.
const button = document.querySelector('#save');
button.addEventListener('click', saveForm());
function saveForm() {
console.log('saved');
}
Reply with what is broken and how you would fix it.
Calling saveForm() right there runs it immediately and passes its return value (undefined) as the handler.
button.addEventListener('click', saveForm);
No parens, just pass the reference. Classic one, I still catch myself doing this occasionally when refactoring in a hurry.
:: Copyright KIRUPA 2024 //--