Searchable List Box/Combo Box

I have a big List Box/Combo Box in my .asp application.  The data in the box is populated via a database and is getting quite large.  The problem is that the user can press the first letter and the box will jump to that but that still leaves a lot of scrolling to do.  Is there any way with JS to basically 'search' that box - or at least be able to enter more than the first character and have it jump to that portion of the list?  Thanks
LVL 1
Tom FI.T. and Support Staff ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

override_y2kCommented:
/*
 * ComboSearcher.js
 *
 * Usage:
 *  Add the following events to your SELECT Tag.
 *  onfocus="initComboSearch();" onkeydown="searchComboBox(this);"
 *
 */


var comboSearchChars;
var KEY_BACKSPACE = 8;

function initComboSearch() {
  comboSearchChars = "";
}

function searchComboBox(theComboBox) {
  //undo the keypress to avoid the default browser behaviour
  window.event.returnValue = false;
 
  var keyCode = window.event.keyCode;
  if (keyCode == KEY_BACKSPACE) {
    comboSearchChars = comboSearchChars.substring(0, comboSearchChars.length-1);
  } else {
    var keyChar = String.fromCharCode(keyCode);
    comboSearchChars += keyChar.toLowerCase();
  }

  for (var i = 0; i < theComboBox.length; i++) {
    var comboValue = theComboBox.options[i].text.substring(0, comboSearchChars.length);
    comboValue = comboValue.toLowerCase();
    if (comboValue == comboSearchChars) {
      theComboBox.options[i].selected = true;
      return;
    }
  }
}


That way if you have James, Jean, John and Olive if you type JO, it will go to John, rather than Olive.

Regards,

o2k

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.