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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:22:07+00:00 2026-06-13T04:22:07+00:00

I am finding it difficult to synchronize blur and click events. The scenario is

  • 0

I am finding it difficult to synchronize blur and click events. The scenario is as follows: I have a page in which i have a textbox and a button. Now I have a blur event handler for the textbox, which basically makes an AJAX request and updates some part of the page. Also I have a click handler for the button which does some other job.

Now the problem here is that since I have a blur event handler on the textbox, when I enter something in the text box and directly click the button, it fires both blur and click events (as expected). The problem is synchronizing the two since the click handler should only execute once the blur handler has returned (if there was any blur event).

Sample code is as follows:

 $('#textbox').on('blur', function(){
//make an ajax request
});

$('#btn').on('click',function(){
//wait for the blur event to finish(if any) 
// then execute the code
})
  • 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-13T04:22:09+00:00Added an answer on June 13, 2026 at 4:22 am

    Try something like this:

    http://jsfiddle.net/8m7j5/2/

    var blurring = [];
    var expecting = false;
    
    $(document).ready(function () {
        $('#textbox').on('blur', function () {
            // make an ajax request
    
            console.log("TEXTBOX BLURRED");
    
            blurring.push(1);    // Flag a new blur event
    
            $.ajax({
                url: "/echo/json/",
                complete: function () {
                    setTimeout(function () {    // Simulate AJAX request taking 2 seconds
                        console.log("AJAX REQUEST COMPLETE");
                        blurring.pop();    // Flag completed blur event
                        checkClick();
                    }, 2000);
                }
            });
        });
    
        $('#btn').on('click', function () {
            // wait for the blur event to finish(if any)
            // then execute the code
    
            console.log("ACTUALLY CLICKED BUTTON");
    
            expecting = true;
            checkClick();
        });
    });
    
    function checkClick() {
        if (expecting && blurring.length < 1) {
            console.log("CHECKING: EXPECTING CLICK AND NO MORE BLUR EVENTS");
            expecting = false;
            clickFunction();
        } else {
            console.log("CHECKING: EITHER NOT EXPECTING OR BLUR EVENT(S) STILL OCCURRING");
        }
    }
    
    function clickFunction() {
        console.log("EXECUTING CLICK FUNCTION");
    
        // Put your actual click code here
    }
    

    What you actually want to happen when the button is clicked, put in clickFunction.

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

Sidebar

Related Questions

I have an assignment which I'm finding very difficult. Any help would be appreciated.
All, Below is the lambda expression which I am finding difficult to reduce i.e.
There are two formulae which I am finding it difficult to represent in MATLAB
i am finding it difficult figuring our how the jcombobox actionperformed event works. I
I'm finding it difficult to understand how ActiveAdmin(http://activeadmin.info/) works with existing controllers I have
I have never used VSTO and I am finding it difficult to find a
I'm finding it difficult to get started in Objective-C. I'm executing the following code
I'm finding it difficult learning how to formulate subqueries in MySQL For example, this
I'm finding it difficult to find a decent example on how to implement a
I am new to prototype and finding it a lot more difficult than jquery.

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.