Your handler never stops the submit, so you’ll get the alert and then the form still submits (and on a real page, refreshes/navigates). Call e. preventDefault() when invalid, and don’t rely on email being a magic global from the id (that’s flaky); grab the input explicitly: