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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:00:02+00:00 2026-05-26T17:00:02+00:00

I have a javascript program to filter a list of things in a HTML

  • 0

I have a javascript program to filter a list of things in a HTML select control by typing a regular expression into an input (text) box. I can do the following to correctly filter a specific select control:

$(function() {
    $('input[data-filterable]').keyup(
        function() {
            filter = new filterlist(document.myform.myselect);   
            filter.set(this.value);
        });
});

but I have used a custom attribute (something one can now do in HTML5) called data-filterable. The attribute will store the name of the select control that is to be filtered so that JS can use the name of the control to filter the list. This would be a good idea because I will have a general function to filter any select box rather than a specific one.

Any ideas how I do this? I need something like this in the HTML:

<input data-filterable='{"to":"#selectbox1"}' size="30" type="text" />

but I’m not sure exactly what I’m doing here and what to do with the JS.

Thanks guys :).

  • 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-26T17:00:03+00:00Added an answer on May 26, 2026 at 5:00 pm

    Try this:

    <input data-filterable="#selectbox1" size="30" type="text" />
    
    $(function() {
        $('input[data-filterable]').keyup(
            function() {
                filter = new filterlist($($(this).data('filterable'))[0]);   
                filter.set(this.value);
            });
    });
    

    To break down the expression $($(this).data('filterable'))[0]:

    $(this) wraps this in a jQuery wrapper. In our context, since it’s a jQuery keyup event handler, this references the <input> DOM node.

    $(this).data('filterable') retrieves the contents of the data-filterable attribute as a string. In our case, it’s #selectbox1.

    After that this string gets passed in to jQuery as a selector: $($(this).data('filterable')).

    Finally, we take the 0’th element of the returned array which should be the DOM element of the target selectbox. Of course, if there isn’t a selectbox which fits the selector this will fail rather miserably. If you suspect that this is a real scenario, check the .length of the returned array first.

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

Sidebar

Related Questions

i have this html and javascript program code for log in window. my html
I have javascript code embedded inside a html template file. When I load this
I have JavaScript code which copies the value of input file and paste it
I have the following JavaScript program saved in a file pre.js : var pre
I have a simple Javascript program that displays a small rectangle in a canvas.
i have written a snake program using javascript.. the problem is that the snake
In a Javascript program I have an object with the following two (simplified) functions:
I have a checkbox that when clicked, calls a javascript program that calls grid.PerformCallback(),
I usually script/program using python but have recently begun programming with JavaScript and have
I have recently converted 10 JavaScript files into one file, which I then run

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.