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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:47:26+00:00 2026-06-02T11:47:26+00:00

A while back I found some code that allows you to filter the contents

  • 0

A while back I found some code that allows you to filter the contents of a SELECT by typing in a text element. It works well however, over time the performance degrades pretty badly. I’m not sure if it is the filter code or the way in which I am activating it.

The SELECT shows up in a modal dialog (bootstrap) so I have the following code:

$('#myModal').on('shown', function () {
  $(".focusable").val("").focus();
  var select = $('#myModal').find(".modal-body").find("select");
  var text = $('#myModal').find(".modal-body").find("input[type='text']");
  select.filterByText(text, true);
});

And here is the filter code:

jQuery.fn.filterByText = function (textbox, selectSingleMatch) {
  return this.each(function () {
    var select = this;
    var options = [];
    $(select).find('option').each(function () {
      options.push({value:$(this).val(), text:$(this).text(), data:$(this).data("short-name")});
    });
    $(select).data('options', options);
    $(textbox).bind('change keyup', function () {
      var options = $(select).empty().data('options');
      var search = $.trim($(this).val());
      var regex = new RegExp(search, 'gi');

      $.each(options, function (i) {
        var option = options[i];
        if (option.text.match(regex) !== null) {
          var copyOption = $('<option>').text(option.text).val(option.value);
          copyOption.data("short-name", option.data);
          $(select).append(copyOption);
        }
      });
      if (selectSingleMatch === true &&
          $(select).children().length === 1) {
        $(select).children().get(0).selected = true;
      }
    });
  });
};

Can anyone shed some light on where my performance issue(s) might be and how to solve it?

  • 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-02T11:47:28+00:00Added an answer on June 2, 2026 at 11:47 am

    reading through the comments I would suggest to add the following:

    $(textbox).bind('change keyup', function(event) {
      console.log(event);
      // your code
    });
    

    Is the event triggered more than once on a single keyup after some times the dialog is shown?

    $('#myModal').on('hidden', function () {
      $('#myModal').find(".modal-body").find("input[type='text']").off("change keyup");
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A while back a found a great-looking framework that allowed .net developers to implement
I wrote some code to save images on the SD Card a while back.
A while back I created a lightbox plugin using jQuery that would load a
a while back, CNET had these really cool Social Share buttons, that when you
A while back I was playing with methods using variable-length argument lists (java) that
I little while back I posted this question . I have updated that question
A while back I was following some tutorials an assembly. I was running it
I removed a class a feature from my code a while back and committed
While searching for how to do this, I found some vague discussion about different
Recently I have been refactoring some of my C# code and I found a

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.