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.
You’re calling saveForm() immediately and passing its return value to addEventListener, so the log happens on page load and the click handler is basically undefined. Pass the function reference instead: button. addEventListener('click', saveForm) (or () => saveForm() if you need to wrap it).
:: Copyright KIRUPA 2024 //--