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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:57:10+00:00 2026-05-23T20:57:10+00:00

I have a #search element, which when the keyup event occurs should fire a

  • 0

I have a #search element, which when the keyup event occurs should fire a function. This function should only fire if keyup hasn’t occurred in a set amount of time (say 500 milliseconds for example). This will prevent search results from updating every letter that is pressed. The problem is that with backbone.js, I have my events in a hash and the one that is applicable looks like:

'keyup #search' : 'setSearch'

which calls the setSearch() function when the keyup event occurs. I’m not really clear on how to handle it at this point. I’ve tried a variety of things, but nothing can maintain the timer past the function ending.

I have something like so:

setSearch: function(event) {
            var timer = window.setTimeout( function() {
                // run function here
                alert('fired');
            }, 500);
    },

rather than the alert('fired'), I’ll have my own function run. I can see why this code doesn’t work (a timer is set for every keyup event that occurs. But I still don’t have a clear idea on what else I could try.

  • 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-23T20:57:12+00:00Added an answer on May 23, 2026 at 8:57 pm

    You need an instance variable in your view that stores the timer ID, then you can stop it and restart it as needed:

    setSearch: function(event) {
        var self = this;
        if(self.timer)
            clearTimeout(self.timer);
        self.timer = setTimeout(function() {
            alert('fired');
            self.timer = null;
        }, 500);
    }
    

    So, if the timer is already running, you call clearTimeout to stop it, start a new timer, and store the timer ID in self.timer (AKA this.timer). You’ll also want to reset the stored timer ID in the timer’s callback function or your setSearch won’t do anything after its timer has fired once. And all the self business is just to capture this for use in the timer’s callback function.

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

Sidebar

Related Questions

I have this code which iterates over a tree, doing a depth-first search. Every
if i have a search function for my site and i want the user's
I have a jQuery UI which is doing simple autocomplete function. Autocomplete is coming
I have search in MSDN and I can't figure where are the POST parameters
I have a search form with a query builder. The builder is activated by
I have a search box that doesn't have a submit button, I need to
I have a search form in an app I'm currently developing, and I would
I have a search form on each of my pages. If I use form
I have a search program that will be looking at a database from a
I have a search query that I'm inheriting and attempting to optimize. I am

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.