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 6224789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:43:48+00:00 2026-05-24T08:43:48+00:00

Every time I submit a form by pressing enter , the click() function on

  • 0

Every time I submit a form by pressing enter, the click() function on the first <button> in the associated form is getting triggered. The problem (other than the fact that I just find this behavior odd) is that it is literally a click event, indistinguishable from actually clicking on the button. If it triggered the even on my submit button, I’d be fine with it.

The issue is that in this case the first button has nothing to do with the actual form, it’s actually in a hidden popup.

So the exact question: Why is this happening? How do I prevent it? How do I distinguish this “fake click” event from a real one?

(this is a very simplified example; actual code is using jQuery (in case jQuery happens to acknowledge this and there is a fix for it), but the actual issue has nothing to do with jQuery)

<form>
    <input>
    <button onclick="alert('button A click');">Button A</button>
    <button onclick="alert('button B click');">Button B</button>
    <input type="submit" value="Submit Button">
</form>

http://jsfiddle.net/NexHC/2/

Please, no suggestions to “move the button”

  • 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-24T08:43:48+00:00Added an answer on May 24, 2026 at 8:43 am

    -snip-

    Edit

    <form>
        <input>
        <button type="button" onclick="alert('button A click');">Button A</button>
        <button type="button" onclick="alert('button A click');">Button B</button>
        <input type="submit" onclick="alert('button Submit click');" value="Submit Button">
    </form>
    

    Actually I take it back… the reason is a lot more concrete and simple than that. Submit is the default type for <button> as specified by the w3c. Therefore, by leaving the button type attributes blank on your form, you were making three submit buttons and it was picking the first when you hit enter (love the <kbd> styling on this site :P). See here for w3c info and here for the updated fiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Something is eluding me here. Every time I press the submit button, the form
I am getting a conversion error every time I try to submit a date
I'm using Spring 3 and every time I submit a HTML form to a
I'm working on a simple, one field, form that works with AJAX. Every time
My Servlet app. gets called twice every time the user submits a form: The
I have a form that submits a jQuery .ajax event every time menu's value
I can't get Google Chrome to submit my form. It's getting pretty ridiculous. It
I have web form in which I have to make sure that 'SUBMIT' button
every time click login it return me to the login screen this is my
I made a simple form with radio buttons and submit button. On submit, check()

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.