Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6171367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:12:04+00:00 2026-05-23T23:12:04+00:00

I have a form with multiple submit buttons and I’m listening for the ‘submit’

  • 0

I have a form with multiple submit buttons and I’m listening for the ‘submit’ event via JavaScript. I want to know which submit button or form field (if the user pressed ‘Enter/Return’) triggered the submit event. Is there a way to get the HTML element that the user clicked on or pressed ‘Enter/Return’ in?

Update since people aren’t understanding me:

This is via JavaScript before the form is submitted. No server-side detection allowed. I also need to handle the form being submitted via the user pressing Enter or Return.

Code

<form action="" method="POST">
    <input type="text" name="first_name">
    <input type="text" name="item">
    <input type="submit" value="Add item">
    <input type="submit" value="Submit">
</form>

Clicking ‘Add Item’ or pressing Return/Enter inside name=”item” will add another form field.

Final Note

As far as I can tell, there isn’t a way to detect which form field triggered a form submission. If you need to prevent submitting a form that has multiple buttons and/or from Enter/Return, you’ll need to use <input type=”button”> and bind event handlers to the form fields you want to stop form submission from.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:12:04+00:00Added an answer on May 23, 2026 at 11:12 pm

    If you have multiple submit buttons, the way you can tell is by giving each of them a unique name attribute, like this:

    <input type="submit" name="submit1" value="Submit 1"/>
    <input type="submit" name="submit2" value="Submit 2"/>
    <input type="submit" name="submit3" value="Submit 3"/>
    

    The one that is focused is sent along with the form submit, so if you clicked the one with a name of “submit2”, that would come through in the form POST (or GET). If enter is hit, the first button in the source (in this case submit1) is considered the default and is sent along. You could set it to display:none to use as a dummy for detecting whether enter was pressed vs actually clicking a submit button.

    EDIT:

    In response to your comments, to capture the enter key getting pressed in certain elements you can do this with jQuery.

    Note, you’ll need to give first_name and add_item id attributes, and turn add_item into a type=”button” instead of type=”submit”.

    HTML:

    <form action="" method="POST">
        <input type="text" name="first_name"/>
        <input type="text" id="item" name="item"/>
        <input type="button" id="add_item" value="Add item"/>
        <input type="submit" value="Submit"/>
    </form>
    

    JS:

    $("#item").keydown(function(event){
        if(event.keyCode == 13) {
            addFields();
    
            event.preventDefault();
            event.stopPropagation();
        }
    });
    
    $("#add_item").click(function(event) {
        addFields();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to have multiple submit buttons. I have a form which creates an
I have a form with multiple submit buttons. When one of those button is
I have a form on an HTML page with multiple submit buttons that perform
I have multiple buttons in a form (all are type 'submit'). I would like
I have a form with a simple text field and multiple submit buttons. When
I have a single form with multiple submit buttons that have same value. Example:
I have quite a big form with multiple (over 100) submit buttons in it.
Possible Duplicate: Multiple submit buttons in an HTML form I have web form with
I have a form made up of multiple, optional subparts - each of which
I have a group of radio buttons in a multiple select quiz form and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.