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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:31:13+00:00 2026-05-24T04:31:13+00:00

I have an input text which is used to filter and sort the contents

  • 0
  • I have an input text which is used to filter and sort the contents of a select dropdown.
  • The filtration/selection function filterSort() is called on keyup on the input text.

Code

$(inputTextField).keyup(function() 
{
     //lot of logic to filter the options of a select dropdown and sort them based on the text of inputTextField


});

Problem
The filtration/sorting logic is working fine now. But I realized that while a user is typing, there are multiple threads executing the code inside filterSort(). So, I want to stop execution of the code inside the keyup() if another keyup() has happened, because there is no need to continue with an older thread as its results will be anyway discarded. Never encountered such a situation. How do I do this?

I am not yet sure if that is functionally causing any problem, I think I am getting the correct filtered+sorted results in the end.

  • 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-24T04:31:14+00:00Added an answer on May 24, 2026 at 4:31 am

    A solution would be to delay the filtering operation with setTimeout() and reset the timer every time the user presses a key. jQuery’s data() method can be used to keep track of the timer identifier:

    $(inputTextField).keyup(function() {
        var $this = $(this);
        var timer = $this.data("timer");
        if (timer) {
            window.clearTimeout(timer);
        }
        $this.data("timer", window.setTimeout(function() {
            // Lots of logic to filter and sort the options...
        }, 250));
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an text input box which needs to be used as a search.
I have two input text boxes which are decimal. The sum of the two
I have an input text field which has style: visibility: visible or style: visibility:
I have an input text field, which has a value something by default, but
I have an input of type text , from which I have already entered
I have an input field which has a placeholder text. I want one word
I have the following text input on a budget calculator form which displays the
I have a form in which I have 30 input boxes and 10 text
I have a Date Input text box generated by jquery Date Picker which is
I have a input type=file tag in my html which allows user to select

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.