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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:37:04+00:00 2026-06-06T23:37:04+00:00

I have a table containing in every row one cell inside which is checkbox

  • 0

I have a table containing in every row one cell inside which is checkbox and label for that checkbox.

What I’m trying to do it to hide rows based on inputed text.

Basically this is list on names and I want to filter/hide those that don’t contain entered text.

This is my function:

$(function () {
$('#user_name').keyup(function () {
    if ($.trim($('input#user_name').val()) == '') {
        $('table.myList >tbody >tr').each(function (index, value) {
            $(this).css("display", "block");
        });
    } else {
        $('table.myList >tbody >tr').each(function (index, value) {
            if ($(this).find('td > label').length > 0) {
                if ($(this).find('td > label').html().toLowerCase().indexOf($.trim($('input#user_name').val()).toLowerCase()) >= 0) {
                    $(this).css("display", "block");
                } else {
                    $(this).css("display", "none");
                }
            }
        });
    }
});
});

This code works, if my table has 40 records its fast, but when I increment list to 500 it slows down and crashes my browser after time.

I’m looking for a way to improve this code to work faster.

Here is link to mock-up code: http://jsfiddle.net/gGxcS/

==UPDATE==

Here is my final solution based on answers of @scessor and @nnnnnn:

$(function () {

var $tableRows = $('table.myList tr');
var lastInput = '';

$('#user_name').keyup(function () {
    var sValue = $.trim($('input#user_name').val());
    if(lastInput==sValue) return;
    if (sValue == '') {
        $tableRows.show();
    } else {
        $tableRows.each(function () {
            var oLabel = $(this).find('label');
            if (oLabel.length > 0) {
                if (oLabel.text().toLowerCase().indexOf(sValue.toLowerCase()) >= 0) {
                    $(this).show();
                } else {
                    $(this).hide();
                }
            }
        });
        lastInput=sValue;
    }
});

$('img.removeSelections').click(function () {
    $('table.myList input[type="checkbox"]').prop("checked", false);
})
});
  • 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-06T23:37:05+00:00Added an answer on June 6, 2026 at 11:37 pm

    Can you test this code (with lot of elements)?

    $(function () {
        $('#user_name').keyup(function () {
            var sValue = $.trim($('input#user_name').val());
            if (sValue == '') {
                $('table.myList tr').show();
            } else {
                $('table.myList tr').each(function() {
                    var jThis = $(this);
                    var oLabel = jThis.find('label');
                    if (oLabel.length > 0) {
                        if (oLabel.text().toLowerCase().indexOf(sValue.toLowerCase()) >= 0) {
                            jThis.show();
                        } else {
                            jThis.hide();
                        }
                    }
                });
            }
        });
    });
    
    • Don’t call functions with same parameters twice (e.g. $.trim($('input#user_name').val());).
    • Use short selectors.
    • Use jquery each only if necessarry (e.g. don’t needed here: $('table.myList >tbody >tr').each(function (index, value) {).

    === UPDATE ===

    If somebody holds backspace to long, it will set all trs visible again and again. To prevent this you could check, if the last value is equal to the current value. If true, do nothing.

    === UPDATE ===

    To uncheck all checkboxes, it depends on your jQuery version.

    With jQuery 1.6 and higher:
    $('table.myList input[type="checkbox"]').prop("checked", false);
    Before:
    $('table.myList input[type="checkbox"]').attr("checked", false);

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

Sidebar

Related Questions

I have table containing data . In every row there is a checkbox plus
I have an sql table containing the gps coordinates of a device, updated every
I have data table containing one column as FilePath. FilePath D:\New folder\link.txt D:\New folder\SharepointMigration(Work
I am trying to implement hierarchyID in a table (dbo.[Message]) containing roughly 50,000 rows
I have a huge table, which has 3 columns and about 333,000 rows. The
So I have a table with only two columns and one row. The second
I have a large table (potentially millions of rows) that in its naive form
I have a table containing users... one way or another some users were doubled
i have a huge access table containing about 400000 rows . what sql query
I have a table containing a series of names, events and dates. I've created

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.