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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:12:08+00:00 2026-06-02T22:12:08+00:00

I would like to prevent user from submitting dialog form twice. Here is my

  • 0

I would like to prevent user from submitting dialog form twice.

Here is my submit code:

$('form', dialog).submit(function () {
    if (dialogSubmitted) { return false; }
    dialogSubmitted = true;
    ...
    ...
});

Where dialogSubmitted is a variable indicating if the form is already submitted. The problem is that it doesn’t work. When I open the dialog and I press Enter twice (quickly) the form is submitted twice.

Any idea?

Thanks.


UPDATE

Here is another attempt which also failed when I press enter key twice very quickly:

    $('form', dialog).one('submit', function (evt) {

        evt.preventDefault();

        $(this).on('submit', function (evt) {
            evt.preventDefault();
        });

        $.post($(this).attr('action'), $(this).serialize(), function (data, status) {
            $('#my-modal').modal('hide');
            ...
            ...
        }).error(function (error, status, a, b) {
            $('.modal-body p.body').html(error.responseText);
            writeError('msgError', pStopIndex.validationFailed);
        });

        // Unbind form submitting
        $('form', dialog).unbind();
        return false;
    });

As you can see, I do ajax post (in place of classic form submit). Maybe the problem is there?

Here is the capture of traces from Google Chrome:

enter image description here

We can see there are 2 posts. Only occurrs when I press enter key twice quickly or click submit button twice quickly.

Any idea? Thanks.

  • 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-06-02T22:12:10+00:00Added an answer on June 2, 2026 at 10:12 pm

    just use one() method

    see example fiddle : http://jsfiddle.net/MpBCL/

    $('form', dialog).one('submit', function (evt) {
    
        /* prevent default action */
        evt.preventDefault();
    
        ...
        /* code to be executed once */
        ...
    
        /**
         * disable default action (this handler will be attached after first 
         * submit event and it will prevent any further submit action
         */
        $(this).on('submit', function (evt) {
           evt.preventDefault();
        });
    
    });
    

    further reference: http://api.jquery.com/one/

    Description: Attach a handler to an event for the elements. The handler is executed at most once per element.

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

Sidebar

Related Questions

Here's an example of the sort of query I would like to prevent from
I would like to prevent a user from either: Copy and pasting from the
I would like to know how to prevent the user from entering data into
I would like to prevent the user from clicking on saturdays/sundays (week-ends) when he
I would like to prevent a property from being exposed via my WCF web
If you have some blocks of code that you would like to prevent execution
I find the question in some sites like ow would you prevent someone from
I would like prevent anyone trying to access my website thro' code. Code in
I have one of my activities which I would like to prevent from rotating
I would like to prevent Tomcat from listing the files in a directory when

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.