This script works well for searching thru a SELECT list but doesnt work so
well with the MULTIPLE option. I need to modify it to work for a SELECT
MULTIPLE but I have no idea where to begin, any tips?
<script>
var searchString = "";
function clearSearchString() {
searchString = "";
}
function betterSelect(selectName, formName) {
// Get the keypress from the select box
var keyCode = event.keyCode;
var keyChar = String.fromCharCode(keyCode).toLowerCase();
var selectBox = eval("document." + formName + "." + selectName);
var optionsCount = selectBox.options.length;
var i;
// Check to see if the keypress is something we should care about...
if ((keyCode == "8") || (keyCode == "46"))
// Delete or backspace decrement the searchString
searchString = searchString.slice(0,-1);
} else if ((keyCode == "38") || (keyCode == "37")) {
// Up or left arrow move to the preceeding item in options list
if (selectBox.selectedIndex > 0) {
selectBox.selectedIndex --; }
return false;
} else if ((keyCode == "40") || (keyCode == "39")) {
// Down or right arrow move to the next item in the options list
if (selectBox.selectedIndex < (optionsCount - 1)) {
selectBox.selectedIndex ++; }
return false;
} else if (keyCode == "27") {
// Escape clears the searchString variable
searchString = "";
window.status = "";
return false;
} else if (keyCode == "188") {
// Comma dealt with manually
searchString = searchString + ",";
} else
// Add the new keypress to the searchString variable (default)
searchString = searchString + keyChar;
}
// Display keypresses in the status bar at the bottom of the window
var statusDisplay = searchString.toUpperCase();
window.status = "Narrowing select menu items (press 'Esc' to clear): " +
statusDisplay;
// Advance to the selected item
for(i = 0 ; i < optionsCount; i++) {
var optionItem = selectBox.options[i].text;
// Uncomment this routine to selectively exclude portions of a substring
(e.g. commas, etc.)
/* var findComma = optionItem.indexOf(", ");
if (findComma != -1) {
optionItem = optionItem.substr(0, findComma) +
optionItem.substr(findComma + 2, optionItem.length);
} */
var optionItemSubString =
optionItem.substring(0,searchString.length).toLowe rCase();
// Check each option item for text like the current searchString
if (optionItemSubString == searchString) {
// If there is a match, select that item and exit loop
selectBox.options[i].selected = true;
break;
}
}
}
</script>
<FORM ACTION="" METHOD="POST" NAME="summary">
<select name="Customer_Name" onkeydown="return false;"
onkeyup="betterSelect('Customer_Name', 'summary');"
onclick="clearSearchString(); window.status = '';" size="1" >
<option>aaa</option>
<option>bbbb</option>
<option>cc</option>
<option>abc</option>
<option>123</option>
</select>
</FORM>