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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:13:58+00:00 2026-05-22T19:13:58+00:00

actually I can not find an exact title for this problem. But I can

  • 0

actually I can not find an exact title for this problem. But I can describe it so that you know what I need.
say I have a button#pressme, and I would like bind a click event handler to it. Inside the function handler, I will use ajax to get some data from the sever and then parse the data to update a div#status’s text, for example: from N/A to updated/not updated. Because the data is always changing, I would like to add another function to change the div#status back to N/A.
Here is what I come up with this purpose:

 $("button#pressme").bind("click", function(){
           $.ajax{(
                   type:"POST",
                   .....
                   success: function (xml, status) {
                     .....
                     $("div#status").text("updated");
                     setTimeout(function(){$("div#status").text("N/A")}, 20000);
                   },
                   error: ....
                  )};
  });

This seems working as I planned, because the text will change back to “N/A” after 20 seconds. However, I found a problem exists: if the user keep clicking the button: say the user click button 1st to change the text to “updated”, and then after 18seconds, clicked again to change the text to “not updated”. And then, only after 2seconds, the text will change back to “N/A”, because the 1st setTimeout function got executed.

If I want to remember the last time’s user click, and only update the div’s text 20 seconds after the user’s last click? How to achieve this easily?

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-05-22T19:13:59+00:00Added an answer on May 22, 2026 at 7:13 pm
    1. retain a handle to the timer:

      timerId = setTimeout(...);

    2. every time you restart the timer, clear the old one first:

      clearTimeout(timerId);

    e.g.:

    $("button#pressme").bind("click", function() {
           var that = this;
           $.ajax{(
                   type:"POST",
                   .....
                   success: function (xml, status) {
                     var timerId = $(that).data('timerId');
                     .....
                     $("div#status").text("updated");
                     if (timerId) { 
                         clearTimeout(timerId);
                     }
                     timerId = setTimeout(function(){$("div#status").text("N/A")}, 20000);
                     $(that).data('timerId', timerId)
                   },
                   error: ....
                  )};
      });
    

    EDIT updated to show using the jQuery .data() method to store and retrieve the timerId on a per-element basis.

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

Sidebar

Related Questions

The title is not exact, but I can't express it better in a single
I'm not sure what this practice is actually called, so perhaps someone can edit
I could not find this anywhere. I fetch some JSON from an API that
Last year, Scott Guthrie stated You can actually override the raw SQL that LINQ
Can anyone link me to a decent c++ tutorial that's actually currently in date?
Actually, this question seems to have two parts: How to implement pattern matching? How
Actually, I'm using this way. Do you have a better way? private bool AcceptJson(HttpRequest
Actually my question is all in the title. Anyway: I have a class and
1st of all: I'm not a programmer, never learnt programming/algorithms. Actually I have to
I have a JQuery (using JQuery 1.4.2) problem that exhibits only in IE8 in

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.