Max wrote:
Quote:
What i want is the possibility to type a second letter:
If I press the letter A, the drop-down list points directly to the
first value in the list
of values starting with an 'A' ==> AACC and if i press 'B', this
should point to 'ABCDD',
and again if i press a third letter 'K', this should point to 'ABK'. |
Weitgehend ungetesteter Quickhack, sollte in MSIE5+, Mozilla, NN6+
und Opera 6+ funktionieren:
// global variables
var lcd = null; // for storing timestamp
var tcs = ''; // for collecting input
var lim = 1000; // forget previous input after lim milliseconds
function sku(se, eo) { // args: select object, event object
var c = String.fromCharCode(eo.keyCode); // typed character
var ctm = new Date().getTime(); // new timestamp
var tdi = lcd? ctm - lcd : lim; // millisecs since last keyup
if (tdi >= lim) tcs = c; else tcs += c; // forget or add?
lcd = ctm; // store new timestamp
var ret = new RegExp("^" + tcs); // string to look for
for (var i=0; i<se.options.length; i++) { // until first option
if (se.options[i].value.match(ret)) { // matches it
se.selectedIndex = i; // if so, select that option
break; // and done
}
}
}
....
<select ... onkeyup="sku(this, event)">
ciao, dhgm