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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:35:12+00:00 2026-05-25T19:35:12+00:00

I have disabled my enter key so that I can do an ajax submission,

  • 0

I have disabled my enter key so that I can do an ajax submission, but I want to make sure that the form isn’t submitted twice if the user hits enter twice before the response from the server comes back.

Here I have disabled the enter key and assigned a function to it called submitForm():

$(document).ready(function(){
    offset = $("#quantity").html();
    $("#lastName").focus();
    $(document).bind("keypress" , function(e){
        if (e.which == 13 && (!$("#notes").is(":focus")) && (!$("#submit").is(":focus"))) {
            submitForm(); return false;
        }
    })
    $("#submit").click(function(){ submitForm(); });
});

I tried to bind() again elsewhere, but it didn’t do anything. I tried preventDefault() in various places, but I think I’m either putting it in the wrong place, or else that’s the wrong thing to do. I can’t seem to get this to work.

I found this: How to disable Enter/Return Key After a function is executed because of it?, but it doesn’t answer my question because in the poster’s example, the script checks to see whether there is anything in the box, but I want to check to see whether I have submitted or not. I’m not sure how to do that. What I would really like to do is disable the enter key until I hear back from the server on the ajax call. Here is submitForm():

function submitForm() {
    $.post("/ajax/files" , $("#files").serialize(), function(data){
        filesReset();
        if (data != "") {
            $("#lastInsert table tbody:last").prepend(data);
            $("#lastInsert table tbody:last tr:first").find("td").hide();
            $("#lastInsert table tbody:last tr:first").find("td").fadeIn(1000);
            $("#lastInsert table tbody:last tr:first").effect("highlight" , {"color": "aqua"}, 1000);

            $("#lastInsert table tbody:last tr:last").remove();
        } else {
            alert("Insert rejected: either insufficient criteria or the server is down.");
            $("#hidden").click();
        }
    });
}

I would prefer not to have to do anything on the server-side, because I need this submit functionality to be as fast as possible (this will be a fast paced data entry form).

  • 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-25T19:35:12+00:00Added an answer on May 25, 2026 at 7:35 pm

    Make use of a variable like this:

    $(function(){
    
        var running = false;
    
        $(document).bind("keypress" , function(e){
            if (e.which == 13) {
                if(running === false) {
                    running = true;
                    submitForm();
                }
                return false;
            }
        })
    
        $("#submit").click(function(){
            if(running === false) {
                running = true;
                submitForm(); 
            }
        });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form with a disabled submit button. Even though the user can't
I have an HTML form on my site that submits via Ajax to a
I am using extjs 4.0.7. I want to disabled tab and Enter key event
i have disabled all the checkboxes except one. On click of that checkbox i
I have a set of checkboxes and have disabled few which I want to
If have an element that maybe disabled on a page, and would like to
I have 2 input boxes that are not disabled. When either gets focus no
I have a Composite that I want to be able to enable/disable programatically. The
I currently have a form with a disabled submit input. In firefox 4.0, if
I have the following function which limits the amount of characters you can enter

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.