Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML: Define the action of "enter" in a <form>

Tags:

html

forms

button

I've got an HTML <form> with a few <button>s and an <input type="submit">:

<form>
    <button>first button</button>
    <button>second button</button>
    <input type="text">
    <input type="submit">
</form>

But when enter is pressed while in the text field, the "first button" is activated instead of the "submit" button.

How can I make enter trigger the "submit" button?

like image 1000
David Wolever Avatar asked Jul 14 '10 20:07

David Wolever


1 Answers

The default behavior of a <button> element is to act like a 'submit' button. Try using <button type='button'> for the non-submit buttons.

like image 69
Phil Avatar answered Oct 05 '22 13:10

Phil