Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submitting a form with the enter button in a form with several submit buttons

I have a form with a simple text field and multiple submit buttons. When the user presses enter, I want to submit the form with a specific submit button, but it looks like the form just chooses the first button instead. Is there any way to tell the browser which submit button to choose when user presses enter? Preferrably without javascript, but I'll take it if that's the only solution.

Edit: I have no other choice than having multiple submit buttons. This is a legacy app.

like image 983
mranders Avatar asked Nov 01 '10 10:11

mranders


People also ask

How do I use multiple submit buttons in one form?

Let's learn the steps of performing multiple actions with multiple buttons in a single HTML form: Create a form with method 'post' and set the value of the action attribute to a default URL where you want to send the form data. Create the input fields inside the as per your concern. Create a button with type submit.

Can I have multiple submit buttons on a form?

yes, multiple submit buttons can include in the html form. One simple example is given below.

Can I have two submit buttons in a Google form?

We cannot create 2 "Submit" buttons, but we can create 2 hyper-links and convert them to buttons. After adding the text field, click on Edit Text to write the text of the button.

How do you submit a form when Enter key is pressed?

To submit the form using 'Enter' button, we will use jQuery keypress() method and to check the 'Enter' button is pressed or not, we will use 'Enter' button key code value. Explanation: We use the jQuery event.


1 Answers

There's no way. The simplest solution is just to ensure that the first submit button in the form is the one you want triggered by the Enter button.

Note that this submit button can be a duplicate of a button elsewhere in the form, and it doesn't have to be visible.

like image 159
Gareth Avatar answered Sep 19 '22 16:09

Gareth