Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 373
user891123 Avatar asked Aug 26 '11 21:08

user891123


People also ask

How do you make button submit on enter?

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).

How do you create a button on a form?

Create a button by dragging a macro to a form In the Navigation Pane, locate the macro that you want the new command button to run, and then drag the macro to the form.

Does the submit button go inside the form?

Yes, structurally the submit button needs to be inside a form element for the document to be valid X/HTML. But visually you can position the submit button anywhere you want with appropriate CSS (float, absolute/relative positioning, etc).


2 Answers

Have you actually tried anything?

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).

like image 53
Bojangles Avatar answered Sep 30 '22 19:09

Bojangles


add a handler to on keydown and check for keycode == 13. Make this submit the form like below

function addInputSubmitEvent(form, input) {
    input.onkeydown = function(e) {
        e = e || window.event;
        if (e.keyCode == 13) {
            form.submit();
            return false;
        }
    };
}
like image 44
kmcc049 Avatar answered Sep 30 '22 19:09

kmcc049