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

  • Home
  • SEARCH
  • 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 785981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:57:53+00:00 2026-05-14T20:57:53+00:00

I use jquery’s .submit() to intercept user’s submit event, however I found a problem.

  • 0

I use jquery’s .submit() to intercept user’s submit event, however I found a problem.

When the user single click the submit button, the form is submitted normally, but if a user deliberately fast click it multiple times, it will submit multiple times, which will cause duplicated data in the database.

What’s the solution for this kind of problem ?

Update: Well, I see some of the advice said disabling the submit button. This should prevent the form being submitted multiple times, but the problem is the form element in my page isn’t refreshed, if I disable it the user won’t be able to submit it anymore, disabling it for 15s may work, but is this the right way to solve this problem ?

  • 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-14T20:57:54+00:00Added an answer on May 14, 2026 at 8:57 pm

    Disabling the submit button is indeed the way to go.

    However, in a lot of cases the server side logic to be executed depends on the presence of the name-value pair of the submit button in question in the request parameter map. Especially in server side component based MVC frameworks like MS ASP.NET and Sun JSF, but also in “simple” forms having more than one submit button. The name-value pair of the pressed submit button is mandatory to determine the action to be executed. Disabling the button would make its name-value pair to completely disappear in the request parameter map and the server side may not take any action or execute the wrong action.

    There are basically 2 ways to go around this:

    1. Use setTimeout() to disable the button after a few milliseconds so that its name-value pair get sent anyway. 50ms is an affordable amount.

      $("form").submit(function() {
          var form = this;
          setTimeout(function() {
              $(':submit', form).attr('disabled', true);
          }, 50);
      });
      
    2. Copy the name-value pair of the actually pressed submit button into a hidden input of the form. This is a bit trickier since this information isn’t available in the submit event of the <form>. You need to let the $(document) capture the last clicked element.

      $("form").submit(function() {
          $(':submit', this).attr('disabled', true);
          $(this).append($('<input/>').attr({
              type: 'hidden',
              name: $.lastClicked.name,
              value: $.lastClicked.value
          }));
      });
      
      $(document).click(function(e) {
          e = e || event;
          $.lastClicked = e.target || e.srcElement;
      });
      

    Update: as per your update:

    Well, I see some of the advice said disabling the submit button. This should prevent the from submit multiple times, but the problem is the form element in my page isn’t refreshed, if I disable it the user won’t be able to submit it anymore, disabling it for 15s may work, but is this the right way to solve this problem ?

    So you’re actually firing an ajaxical request. You could just re-enable the button(s) in the callback handler of the jQuery’s ajax function. Assuming you’re using jQuery.post:

    $("form").submit(function() {
        // Disable buttons here whatever way you want.
    
        var form = this;
        $.post('some/url', function(data) {
            // Re-enable buttons at end of the callback handler.
            $(':submit', form).attr('disabled', false);
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 414k
  • Answers 414k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I learned this recently after I accidentally stumbled upon the… May 15, 2026 at 8:39 am
  • Editorial Team
    Editorial Team added an answer This is probably because you refer to the domain differently… May 15, 2026 at 8:39 am
  • Editorial Team
    Editorial Team added an answer The source release includes a file named macosx-app-template in the… May 15, 2026 at 8:39 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.