I have a page with a text box and a button with JavaScript functionality that starts when the user clicks the button. I would like the functionality to work as well when the user presses the Enter key.
What I'm not sure is whether to make two form inputs and use "return functionname ()" in the onSubmit attribute or capture the press of the Enter key in the text box. My gut instinct is to use a form and onSubmit, which has the advantage of handling unique submission methods at the browser level, but I'm not sure if there are any standards / best practices that prevent this.
I.e:
<form id="myform" onsubmit="return myFunction()">
<input type="text" id="mytextbox">
<input type="submit" id="mysubmit" value="Go">
</form>
against
<input type="text" id="mytextbox" onkeypress="myFunction()">
<input type="button" id="mysubmit" value="Go" onclick="myFunction()">
source