SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict manipura's Avatar
    Join Date
    Apr 2001
    Location
    Calgary,AB
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    searching multi-select box

    Hi all....

    I have a miltiple select box with about 2000 categorys in it. As
    you can guess, it takes a lot of time to scroll down looking for
    what you want..

    I was wondering if it was possible to have a text box that you can
    type in something like 'SH' and keep going, but it will bring up
    the categorys that start with SH.. Kinda like the windows help
    index.

    I have never seen this before so either it can't be done or its
    really hard to do.. But either or, let me know.

    Thanks in advanced.

  2. #2
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might want to check out this post at another site.
    http://www.codingforums.com/showthre...&threadid=9865

    Somebody posted some code that does that.

  3. #3
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's a simple one...
    Code:
    <html>
    <head>
    <script type="text/javascript">
    
    function findOption( e, elem, selName )
    {
    	var key    = ( e ) ? e.which : e.keyCode;
    	var sel    = elem.form.elements[selName];
    	var pat    = new RegExp( "^" + elem.value, "i" );
    	var i      = 0;
    	if ( !findOption.lastMatch ) findOption.lastMatch = 0;
    
    	while( !pat.test( sel.options[i].innerText ) )
    	{
    		if ( i == sel.options.length - 1 )
    		{
    			i = -1;
    			break;
    		}
    		i++;
    	}
    	if ( i == -1 )
    	{
    		sel.selectedIndex = findOption.lastMatch;
    	}
    	else
    	{
    		sel.selectedIndex = findOption.lastMatch = i;
    	}
    }
    
    </script>
    </head>
    
    <body>
    <form>
    <input type="text" onkeyup="findOption( event, this, 'mySelect' );" />
    <br />
    <select multiple="true" size="5" name="mySelect">
    	<option value="aaaa">aaaa</option>
    	<option value="aabb">aabb</option>
    	<option value="baac">baac</option>
    	<option value="baad">baad</option>
    	<option value="bbcc">bbcc</option>
    	<option value="eeab">eeab</option>
    	<option value="eyhj">eyhj</option>
    	<option value="iicc">iicc</option>
    	<option value="rssr">rssr</option>
    	<option value="zooz">zooz</option>
    	<option value="zzzz">zzzz</option>
    </select>
    </form>
    </body>
    </html>
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  4. #4
    SitePoint Addict manipura's Avatar
    Join Date
    Apr 2001
    Location
    Calgary,AB
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help guys! I nothing makes me more happy than doing something that I had no idea how to do in the begining.. Even if most of it was copy/paste....

  5. #5
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This script works great in IE 5+, but it does not seem to work in Netscape 7+ or in Firefox. Does anyone know of any work arounds?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •