|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
drop down list scrolling
Hi,
Is there a way to create a dropdownlist that enables me to browse through its items by typing in more than one letter? For instance, if there are two words "mysql" and "mssql", I'd like the selector to jump to "mysql" in case I type in "my". Thanks, Nima |
|
#2
|
|||
|
|||
|
found it
i found the javascript for it, see below. in addition i had to add the attribute onButtonPress="evalKey()" in the dropdownlist tag.
var tString = ''; var lsf = 0; // last successful index function evalKey() { // Global Variables var i = 0; var success = false; var elem = event.srcElement; var tLowElemText = ''; // Get the unicode char of the keypress var eCode = event.keyCode; // Check if it's a vaid ASCII Character if (eCode == 27){ tString = ''; elem.selectedIndex = 0; } else if ( (eCode > 31) && (eCode < 122)) { // Convert the Code to the corresponding character and add to searchstring tString += String.fromCharCode(eCode); // ... and perform the search starting from the top element in the listbox while (success == false) { i = 0; // Convert everything to lowercase; allows an easy comparison var tLowString = tString.toLowerCase(); // Compose the regexp searchstring ... var rExpr = eval("/^" + tLowString + "/"); while ((i < elem.length)&& (success == false) ) { tLowElemText = elem.options[i].text.toLowerCase(); // success: Position the listbox on the (first) found element if (tLowElemText.search(rExpr) != -1) { elem.selectedIndex = i; success = true; } else { i++; } } // while i < elem.length // if nothing is found in the entire list, the last character of the //searchstring is removed to allow typing the correct 'next' character if (success == false) { tString = tString.substr(0, tString.length-1); } } // while success = false } window.event.returnValue = false; window.event.cancelBubble = true; } |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > drop down list scrolling |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|