HTML form submit on Enter Key | Example code

You don’t need to use JavaScript to do submit button or input on entering key pressed. Just need to mark it up with type="submit", and the other buttons mark them with type="button".

Enter = Submit

HTML form submit on entering example

HTML example code:

Use an <input type=submit> in the form somewhere, which is what gets the automatic Enter Key behavior you’re after.

<!DOCTYPE html>
<html>
<body>

  <form action="form.php" method="POST">
    <input type="text" name="field1"/>
    <input type="button" name="go" value="Submit" />
  </form>
  
</body>
</html>

Output:

HTML form submit on Enter Key

Do comment if you have any doubts and suggestions on this HTML form code.

Note: The All HTML Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.