HighDots Forums  

Re: Selection in a drop-down list

Javascript (German) Programmiersprache JavaScript. (de.comp.lang.javascript)


Discuss Re: Selection in a drop-down list in the Javascript (German) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Dietmar Meier
 
Posts: n/a

Default Re: Selection in a drop-down list - 08-01-2003 , 06:06 AM






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


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.