I have a page that involves a textbox and a button, with JavaScript functionality that triggers when a user clicks on the button. I'd like the functionality to also be triggered when the user presses the Enter key.
What I'm not sure about is whether to make the two inputs into a form and use return functionname() in the onSubmit attribute, or to capture pressing the Enter key in the textbox. My gut instinct is to use a form and onSubmit, which has the advantage of handling unique submission methods on the browser level, but I'm not sure if there are any standards/best practices that discourage that.
That is:
<form id=myform onsubmit=return myFunction()>
<input type=text id=mytextbox>
<input type=submit id=mysubmit value=Go>
</form>
vs
<input type=text id=mytextbox onkeypress=myFunction()>
<input type=button id=mysubmit value=Go onclick=myFunction()>