If you hit enter in an input field in a form, it will automatically submit that form.
Using form elements can also be used to get easy access to FormData objects. By having the form, you can easily create a FormData with the data of all the fields inside that form. Ex:
<form id="catForm" action="https://freecatphotoapp.com/submit-cat-photo">
<input name="url" type="text" placeholder="cat photo URL" value="mycat.jpg">
const form = document.getElementById('catForm')
const data = new FormData(form)
console.log(data.get('url')) // mycat.jpg
Of course if you’re not using the submit action of a form, and using it only for data like this, you’ll need to make sure submit requests get blocked for things like when someone hits enter in a text field. Even if you don’t supply an action, it will default to submitting the form to the current page if you don’t block it.
<form onsubmit="event.preventDefault()" ...