[Javascript] Filtering listbox using textbox input

Peter Brunone peter at brunone.com
Fri May 18 12:40:52 CDT 2001


Here's a general few-step method:

1) Load all values into an array.

2) When the filter value comes back from the user, clear the drop list and
iterate through the array, checking for the filter term with
arrayName[index].indexOf(filterTerm).  If it exists, stick it in the list;
if not, go to the next one.

    In order to get to the text and value of each list, you'll want an index
that goes from zero to formName.listName.options.length, and the properties
you'll change will be formName.listName.options[listIndex].value and
formName.listName.options[listIndex].text .

    Play around with this stuff to see if you get the hang of it; then come
on back if you have any additional questions.

Cheers,

Peter

----- Original Message -----
From: "Michael J. Mahony" <igby at mediaone.net>
To: <javascript at LaTech.edu>
Sent: Friday, May 18, 2001 12:01 PM
Subject: [Javascript] Filtering listbox using textbox input


> OK, this question was posed to me and I'm not sure how to handle
> it.
>
> The form has a drop down list that is populated from a database.
> The data in this drop down is a list of addresses with apartment
> numbers, etc.  The list would look something like this:
>
> 747 South Street, #4
> 747 South Street, #5
> 747 South Street, #6
> 757 South Street, #2
> 757 South Street, #3
>
> What the client wants is a button to the right of the drop down that
> when clicked, brings up another small window with a search box in
> it.  The user types in the search box and that then filters the contents
> of the drop down.  So, using the data above, if the user typed
> "757", the only data in the drop down would be:
>
> 757 South Street, #2
> 757 South Street, #3
>
> Is there a way to do this client-side without a trip back to the server?
> Michael J. Mahony
>
> Hebrews 12:1 --
>     Therefore, since we have so great a cloud of witnesses surrounding
>     us, let us also lay aside every encumbrance, and the sin which so
>     easily entangles us, and let us run with endurance the race that
>     is set before us...
>
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> http://www.LaTech.edu/mailman/listinfo/javascript
>





More information about the Javascript mailing list