I have a form
with two text boxes, one select drop down and one radio button. When the enter key is pressed, I want to call a javascript function (User defined), but when I press it, the form is submitted.
How do I prevent the form
from being submitted when the enter key is pressed?
A react js solution
event.key === "Enter"
More recent and much cleaner: use
event.key
. No more arbitrary number codes!Mozilla Docs
Supported Browsers
A much simpler and effective way from my perspective should be :
native js (fetch api)
Using TypeScript, and avoid multiples calls on the function