Submit form with Enter key without submit button?

Alex picture Alex · Jan 24, 2012 · Viewed 184.6k times · Source

Possible Duplicate:
HTML: Submitting a form by pressing enter without a submit button

How can I submit a form with just the Enter key on a text input field, without having to add a submit button?

I remember this worked in the past, but I tested it now and the form doesn't get submitted unless there's a submit-type input field inside it.

Answer

timmah.faase picture timmah.faase · Jan 24, 2012
$("input").keypress(function(event) {
    if (event.which == 13) {
        event.preventDefault();
        $("form").submit();
    }
});