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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:48:43+00:00 2026-06-18T05:48:43+00:00

I want to fire an ajax action when user make a pause in typing

  • 0

I want to fire an ajax action when user make a pause in typing (instead of after every keypressed). So I made something like this:

When the user stops typing after 3 secs of being idle function done is to be executed … (it is – but why 3 times for long phrases – I would expect it to run only once since I clear timeout after every keydown). What is the problem ?

var timer; 
var interval = 3000; 
$('#inp').keyup(function() {
  timer = setTimeout(done, interval); 
}); 

$('#inp').keydown(function() {
  clearTimeout(timer)  
}); 

function done() {
  console.log('ajax'); 
}

Working example on jsfiddle :
http://jsfiddle.net/vtwVH/

  • 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-18T05:48:44+00:00Added an answer on June 18, 2026 at 5:48 am

    The Problem is you are overwriting the timer variable in your keydown event.

    So if you press another key before the Timout gets cleared e.g keep holding a key

    The reference to the timeOut is lost and you cannot clear it again.

    To fix this you could just clear and set the Timer in the keyUp event like

    var timer; 
    var interval = 3000; 
    
    
    $('#inp').keyup(function(e){ 
        if(timer) {
            clearTimeout(timer);
        }
        timer = setTimeout(done, interval); 
    
    }); 
    
    function done() {
        console.log('ajax'); 
    }
    

    Heres a working fiddle

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

Sidebar

Related Questions

After a user cancels a delete confirmation I want to fire a javascript call
I need guidance in PHP Ajax. I want to develop feature something like Gmail.
I want to fire an event after loading all images. And also, I want
I am using ExtJs virtual keyboard Ref: http://efattal.fr/extjs-dev/examples/virtualkeyboard I want to fire an ajax
I want to fire an AJAX request on the click of a button, But
I want to fire off an AJAX call when a plugin is created that
so I have a series of AJAX events I would like to fire, but
I am using twiiter-bootstrap's tooltip and I want to fire an ajax request, or
i want to fire an event manually using c#. For instance, say if i
I just want to fire an event when an input changes value using 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.