[Javascript] searching a <select> list

Paul Novitski paul at novitskisoftware.com
Wed Jun 2 10:25:30 CDT 2004


Shawn,

Wouldn't you want to search for the character string only at the beginning 
of the list options?

         var regEx = new RegExp('^' + inText, 'i');

Curiously,
Paul



At 04:33 AM 6/2/2004, Shawn Milo wrote:
>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;
>             break;
>          }
>       }
>
>    }




More information about the Javascript mailing list