troubleshooting Question

Filktering Alphabetically

Avatar of Whing Dela Cruz
Whing Dela CruzFlag for Anguilla asked on
JavaScriptHTMLASP
8 Comments2 Solutions200 ViewsLast Modified:
Hi Experts, I have found codes for filtering item but I observed that it only works when I type first 3 letters of the item. I want the item to show at the time I encode its first letter. For example if I type H, I want the all items who start with H will show alphabetically. I have no idea it is possible and please give me a little overview if it is not. Thanks!

function mySearch()
{
    var input, filter, table, tr, td, i;
    input = document.getElementById("myInput");
    filter = input.value.toUpperCase();
    table = document.getElementById("myTable");
    tr = table.getElementsByTagName("tr");
    for (i = 0; i < tr.length; i++)
    {
    td = tr[i].getElementsByTagName("td")[1];
    if (td)
    {
    if (td.innerHTML.toUpperCase().indexOf(filter) > -1)
    {
    tr[i].style.display = "";
    }
    else
    {
    tr[i].style.display = "none";
    }
    }
    }
}
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros