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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:52:49+00:00 2026-05-14T05:52:49+00:00

I have an app that includes a search feature. This feature is implemented by

  • 0

I have an app that includes a search feature. This feature is implemented by having a user type a term in a search bar. Once the user enters 3 characters an ajax call is started. I thought that this would be enough, but it turns out that there’s a bug that I think has to do with timing and the fact that several ajax calls can be done in quick succession by just typing a search term over 4 characters.

What I would like to do is this:

  1. User starts typing
  2. script checks for 3+ characters
  3. once 3 characters are typed, wait (using setTimeout perhaps)
  4. once timeout is reached, check if more characters have been entered
  5. loop 3 & 4 until no more characters have been entered for 1-2 seconds
  6. do ajax call
    … rest is all set …

my question: I know how I would do everything except check for more characters coming in. maybe something like this:

var searchTerm;
function wait(userInput){
   if(userInput.length < 3){return 0;}
   searchTerm = userInput;
   setTimeout(function(){checkInput(userInput);}, 1000);
}

function checkInput(userInput){
   if (userInput == searchTerm){
      ... do AJAX call ...
   } else {
      return 0;
   }
}

That’s just off the cuff and probably wouldn’t run right away. Anyways, any help, tips or direction would be greatly appreciated.

Thanks,
Tim

  • 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-14T05:52:50+00:00Added an answer on May 14, 2026 at 5:52 am

    You need to keep the length of your entered string every time your wait method is called by the html textbox callback.

    If the current string length is equal to the previous length, no characters were added at that interval so you can call the ajax, otherwise keep waiting

        var timerHandle = null;
        var currLen = 0;
        function wait(userInput)
        {
            currLen = userInput.length;
            if(currLen < 3)
            {
                return 0;
            }
    
            if(timerHandle)
            {
                clearTimeout(timerHandle);
                timerHandle = null;
            }
            timerHandle = setTimeout(function(){checkInput(userInput);}, 1000);
        }
    
    
    function checkInput(userInput)
    {
        timerHandle = null;
        if (currLen == userInput.length)
        {
          ... do AJAX call ...
        } else {
          return 0;
       }
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that lets the user search over a number of fields
I have an app that needs to open a new window (in the same
I have an app that executes commands on a Linux server via SSH just
I have a app that I'm deploying to a development server using Capistrano. I'd
I have an app that is failing on the install. The vendor says I
I have an App that will send authenticated emails using System.Net.Mail and System.Net.NetworkCredential my
I have an app that needs to handle very large strings between a SQL
I have an app that I'm writing a little wizard for. It automated a
I have an app that is a combination of asp/asp.net, and both sides depend
I have an app that I've written in C#/WinForms ( my little app ).

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.