# Spot the bug - #61

**URL:** <https://forum.kirupa.com/t/spot-the-bug-61/682193>\
**Category:** web dev\
**Created:** [June 20, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-61/682193 "2026-06-20T07:00:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BobaMilk](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/bobamilk/32/31157_2.png) [@BobaMilk](https://forum.kirupa.com/u/BobaMilk)\
**Post date:** [June 20, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-61/682193/1 "2026-06-20T07:00:08Z")

</div>

Can you spot the form bug?

```html
<form>
  <label>Email</label>
  <input type="email" id="email">
  <button type="submit">Join</button>
</form>
<script>
  document.querySelector('form').addEventListener('submit', (e) => {
    if (!email.value.includes('@')) alert('invalid');
  });
</script>

```

Reply with what is broken and how you would fix it.

---

<div class="post-metadata">

**Author:** ![HariSeldon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/hariseldon/32/31261_2.png) [@HariSeldon](https://forum.kirupa.com/u/HariSeldon)\
**Post date:** [June 21, 2026, 7:20am UTC](https://forum.kirupa.com/t/spot-the-bug-61/682193/2 "2026-06-21T07:20:13Z")

</div>

Your handler never stops the submit, so it’ll still post/navigate even after the “invalid” alert. Call `e. preventDefault()` when it’s invalid (and probably grab the input explicitly instead of relying on the `email` global).

```auto
const emailEl = document.querySelector('#email');
document.querySelector('form').addEventListener('submit', (e) => {
  if (!emailEl.value.includes('@')) {
    e.preventDefault();
    alert('invalid');
  }
});

```

That “implicit globals from id” thing is the part that gets me—once this scales into components/iframes/strict mode, it becomes flaky in a way that’s hard to debug.
