Reputation: 29527
I have a confirm form with two submit buttons: delete and cancel. I'd like for delete to be the default choice, which is activated upon clicking enter. However, neither button is active per default.
I can do something in js, but I really thought that this was default form behavior. Also, there should be an indication of which button is the active one. I'm trying in Chrome.
<form action = "delete/" id = "the_form" method = "post">
<input type = "hidden" name = "the_id" value = "123"></input>
<input type = "submit" value = "Delete" ></input>
<input type = "submit" value = "Cancel" onclick="$('#the_form').addClass('hidden');return false;" ></input>
</form>
Upvotes: 0
Views: 204
Reputation: 943108
Unless you add JavaScript, a form will only be submitted by pressing Enter if a form control inside it has the focus. If the focus is on a button, that button will trigger the form submission. If it is on another input, then it will trigger the first submit button.
Give the delete button the focus using the autofocus
attribute
Upvotes: 1