T Nguyen
T Nguyen

Reputation: 3415

How to submit a form on enter that doesn't have a submit button?

I have a form whose submit "button" is actually a link. Is there a way to submit this form automatically on enter, other than attaching an event handler to check for Enter keypresses? It just seems a little wasteful to me.

Upvotes: 1

Views: 313

Answers (2)

Tak
Tak

Reputation: 11704

I have tested in Chrome and Firefox, it appears that pressing enter in a form field will submit it, whether or not a submit button is present.

If you've found a browser where that isn't the case, you may want to try a submit button in a hidden div, or CSS positioned off-screen.

Or stick to conventions and use a submit button :P

Upvotes: 2

Fourth
Fourth

Reputation: 9351

Throw some jquery on there and submit the form with it:

$("form#formID").submit();

Upvotes: 0

Related Questions