# Spot the bug - #35

**URL:** <https://forum.kirupa.com/t/spot-the-bug-35/681733>\
**Category:** web dev\
**Created:** [May 24, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-35/681733 "2026-05-24T07:00:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Baymax](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/baymax/32/31153_2.png) [@Baymax](https://forum.kirupa.com/u/Baymax)\
**Post date:** [May 24, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-35/681733/1 "2026-05-24T07:00:09Z")

</div>

Quick one: event handling bug here.

```js
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.

---

<div class="post-metadata">

**Author:** ![Ellen1979](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ellen1979/32/31260_2.png) [@Ellen1979](https://forum.kirupa.com/u/Ellen1979)\
**Post date:** [May 25, 2026, 8:20am UTC](https://forum.kirupa.com/t/spot-the-bug-35/681733/2 "2026-05-25T08:20:18Z")

</div>

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).
