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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:17:03+00:00 2026-05-26T18:17:03+00:00

I have a form in my HTML page, containing a label, an input field

  • 0

I have a form in my HTML page, containing a label, an input field and a submit button. Here is an example:

<form id="myForm" action="#">
<label for="myField">My field</label>
<input type="text" id="myField" name="myField" class="required">
<input type="submit" value="Send" />
</form>

In my javascript code, I’m using jQuery to bind an event handler to the submit event.
This event handler overrides the default submit action. It validates the form, performs an animation and then submits the field values to the server using an ajax call. Here is an example:

$("#myForm").bind("submit", function() {
  var valid = $("#myForm").validate().form();
  if (valid) {
    var val = $("#myField").val();
    $("#myForm").animate( /* blah */, function() {
      $.ajax({
        // ajax call here...
      });
    });
  }
  return false; // cancel default submit action
});

Note, that this is a simplified example, my real code is more complex; I also have multiple forms with different behaviours.

Now, I’m looking for an elegant solution to avoid re-entry: currently, the user can hit the return key multiple times, which will result in my event handler being called multiple times, and thus multiple animations and ajax requests. I can’t simply unbind/rebind inside the handler because the handler is overriding the default submit behaviour. Also the handler itself adds callbacks to other functions: animate() and ajax().

The only solution I can think of is to add a boolean semaphore, that I set to true/false as in the following example :

var myFormSubmitExecuting = false;
$("#myForm").bind("submit", function() {
  if (myFormSubmitExecuting) return;
  myFormSubmitExecuting = true;
  var valid = $("#myForm").validate().form();
  if (valid) {
    var val = $("#myField").val();
    $("#myForm").animate( /* blah */, function() {
      $.ajax({
        // ajax call here...
        // when done :
        myFormSubmitExecuting = false;
      });
    });
  } else {
    myFormSubmitExecuting = false;
  }
  return false; // cancel default submit action
});

I would prefer a generic solution that I can write once and apply to all my forms. Any suggestions?

  • 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-26T18:17:03+00:00Added an answer on May 26, 2026 at 6:17 pm

    I was just doing something like this earlier, maybe it might help you. It basically disables the submit field on post and re-enables it on success handler.

    var form = $('form#some-form');
    var submit = $('input[type=submit]', form);
    
    var submit_data = form.serialize();
    
    submit.attr('disabled', true);
    $.post(url, submit_data, function (data) {
        submit.attr('disabled', false);
        ....
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an html file with a form containing a submit button, and an
i have a html page sth.html containing <div id=recoverpass> <h2>Recover Password</h2> <form action=# method=post
I have a form on an HTML page with multiple submit buttons that perform
I have an HTML page with a simple form. When the user clicks submit,
I have a html form that posts to a new page on submit. If
i have a submit page in html . when i submit the form data,
If I have an HTML form, let’s say... <form id='myform'> <input type='hidden' name='x' value='y'>
I have a HTML page containing a form which consists of; text, check boxes
I have an HTML page with a web form. Among other things, it includes
I have a html page with a form. The form has Div which gets

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.