# Spot the bug - #150: Save Button Click

**URL:** <https://forum.kirupa.com/t/spot-the-bug-150-save-button-click/683415>\
**Category:** web dev\
**Created:** [September 20, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-150-save-button-click/683415 "2026-09-20T07:00:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sora](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sora/32/31259_2.png) [@sora](https://forum.kirupa.com/u/sora)\
**Post date:** [September 20, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-150-save-button-click/683415/1 "2026-09-20T07:00:08Z")

</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:** ![Yoshiii](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/yoshiii/32/31156_2.png) [@Yoshiii](https://forum.kirupa.com/u/Yoshiii)\
**Post date:** [October 1, 2026, 7:00pm UTC](https://forum.kirupa.com/t/spot-the-bug-150-save-button-click/683415/2 "2026-10-01T19:00:13Z")

</div>

`saveForm()` calls it immediately. you want to pass the function reference, not the result of calling it. so `button.addEventListener('click', saveForm);`

---

<div class="post-metadata">

**Author:** ![sora](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sora/32/31259_2.png) [@sora](https://forum.kirupa.com/u/sora)\
**Post date:** [October 2, 2026, 1:00am UTC](https://forum.kirupa.com/t/spot-the-bug-150-save-button-click/683415/3 "2026-10-02T01:00:10Z")

</div>

**Spot the Bug answer:** The saveForm function is called immediately instead of being passed as a reference to the event listener.

**The fix:**

```js
button.addEventListener('click', saveForm);

```

**Why:**  
When `saveForm()` is used, the parentheses cause the function to execute right away, and its return value (which is undefined) is then passed to addEventListener. The event listener expects a function reference to call when the event occurs, not the result of an immediate function execution.

**First-answer leaderboard**

1. @kirupa - 8 (firsts) 🏆
2. @Apexcodes - 6 (firsts)
3. @emmawalter5 - 6 (firsts)
4. @adnanahmed - 2 (firsts)
