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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:12:02+00:00 2026-05-17T18:12:02+00:00

I’ve got a search box that is supposed to be able to search data

  • 0

I’ve got a “search” box that is supposed to be able to search data “live”. Right now if I attach the “keypress” event to it and update the results, it works pretty good. However, if they press backspace it doesn’t account for that (refresh the results).

I understand I can probably account for the “backspace” key.

But am I missing any other possibilities? I want any change of the text in the input to be triggering the “event” or calling the refresh function.

The one thing I don’t want to do is set “alarms” or “timers” to check every so often if it has changed.

Ideas?

  • 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-17T18:12:03+00:00Added an answer on May 17, 2026 at 6:12 pm

    To insure that you are triggering your data search after each changing of the text field, you should check if the text field has changed after each .keyup() or .keydown()

    // The following only works for keyboard input, to handle mouse copy / paste
    // see the example after this
    $(function() {                         // <== Doc ready  
    
        var inputVal = $("input").val();   // a variable to hold the text
                                           // set it up w the initial value then see 
                                           // if the input value changes.
    
        $("input").keyup(function() {
    
            // check for change of the text field after each key up
            if(this.value != inputVal)
            {
                // Do your search, etc.
                // ...
    
                // Reset the temp value for the next comparison
                inputVal = this.value
            }
        });
    });
    

    Try it out with this jsFiddle

    To handle mouse copy paste (which Filipe pointed out doesn’t work with the above), jQuery has the option of binding multiple events to one element, and it has a paste and cut event. The problem with these is that they are triggered immediately on paste but BEFORE the input box contents are actually changed, so we need a timeout… in fact a timeout would be a nice feature for the whole thing, so that if the user is typing quickly, then we wait until they are done:

    $(function() {    // <== Doc ready  
    
        var inputVal = $("input").val(), // a variable to hold the text
                                         // set it up w the initial value then see 
                                         // if the input value changes.
    
            timer,
            checkForChange = function() {
                var self = this; // or just use .bind(this)
    
                // we only want to check on the input after the user has settled down,
                // so use a timeout and clear it if another input comes in
                if (timer) { clearTimeout(timer); }
    
                // check for change of the text field after each key up
                timer = setTimeout(function() {
                    if(self.value != inputVal) {
                        // Do your search, etc.
                        $("span").html(parseInt($("span").html(),10) + 1);
    
                        // Reset the temp value for the next time
                        inputVal = self.value
                    }
                }, 250);
            };
    
        $("input").bind('keyup paste cut', checkForChange);
    });
    

    So now we check for the keyboard, for pasting in, and for cutting out.

    Try it out with this jsFiddle


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

Sidebar

Related Questions

No related questions found

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.