Search code examples
htmlformshttp-post

How to make enter the submit button in a form


I have a form for logging into my website. I need to make it so that when the user hits enter, the form submits. How can I do this? Please provide code.

<form id="login" action="myHome.php" method="POST">
    <input type="text" name="email" id="email"/>
    <br/>
    <br/>
    <input type="text" name="password" id="password"/>
</form>

Solution

  • You need to add an <input type="submit"> and hide it with CSS so that the browser knows what to trigger when enter is pressed, yet still not show a button. For the sake of accessibility and ease of use, I'd show the button even if not that many people use it (enter is much nicer).