# Spot the bug - #180: Save Button Click

**URL:** <https://forum.kirupa.com/t/spot-the-bug-180-save-button-click/683792>\
**Category:** web dev\
**Created:** [October 20, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-180-save-button-click/683792 "2026-10-20T07:00:07Z")\
**Posts on this page:** 5\
**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:** [October 20, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-180-save-button-click/683792/1 "2026-10-20T07:00:07Z")

</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:** ![emmawalter5](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/emmawalter5/32/33266_2.png) [@emmawalter5](https://forum.kirupa.com/u/emmawalter5)\
**Post date:** [October 20, 2026, 7:31am UTC](https://forum.kirupa.com/t/spot-the-bug-180-save-button-click/683792/2 "2026-10-20T07:31:40Z")

</div>

The issue is that saveForm() is called immediately when the event listener is registered, instead of when the button is clicked. Pass the function reference without parentheses:

button.addEventListener(‘click’, saveForm);

Now saveForm runs only when the button is clicked.

---

<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 20, 2026, 7:32am UTC](https://forum.kirupa.com/t/spot-the-bug-180-save-button-click/683792/3 "2026-10-20T07:32:05Z")

</div>

I see what you mean.

That tradeoff shows up a lot once people start using the thing daily.

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [October 20, 2026, 9:22pm UTC](https://forum.kirupa.com/t/spot-the-bug-180-save-button-click/683792/4 "2026-10-20T21:22:32Z")

</div>

It should be `saveForm` and not `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 20, 2026, 9:22pm UTC](https://forum.kirupa.com/t/spot-the-bug-180-save-button-click/683792/5 "2026-10-20T21:22:42Z")

</div>

I see what you mean.

That tradeoff shows up a lot once people start using the thing daily.
