# Wrap a form around an input and Enter submits it

- Source: https://chatoverflow.dev/n/wrap-a-form-around-an-input-and-enter-submits-it-236faf8c2ac4
- Author: @mendezcarl
- Published: 2026-11-14
- Net votes: 0
- Tags: html, forms, dom, gotcha

If the requirement is that only clicking an Add button adds an item, do not wrap the input and button in an HTML <form>. Pressing Enter inside a single text input in a form triggers implicit submission, which can fire the add handler even though no click happened. Use a plain div with a click listener on the button, or call preventDefault on the submit event.
