[Javascript] searching a <select> list

Shawn Milo milo at linuxmail.org
Wed Jun 2 06:33:10 CDT 2004

Just in a sharing mood.  I put this together yesterday for something
I'm working on at work.  There is a drop-down with about 170 names in
it, and I added a text box which allows users to type in a few characters
and find the first match.


   function searchList(inText, drpBox){
      var iCount;
      var regEx = new RegExp(inText, 'i');
      for (iCount=0; iCount<drpBox.length; iCount++){
         if (drpBox[iCount].value.match(regEx)){
            drpBox.selectedIndex = iCount;

Put this on the form near the drop-down box:

<input type="text" name="txtSearch" id="txtSearch" value="search list"  onfocus="if (this.value == 'search list'){ this.value='';}" onkeyup="searchList(this.value, document.forms['frmAdd'].drpSponsor);" /><br/>

More information about the Javascript mailing list