faqts : Computers : Programming : Languages : JavaScript : Forms : SELECT

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 13 people (31%) answered Yes
Recently 2 of 10 people (20%) answered Yes

Entry

Is there a JavaScript solution that wont restrict selection by the 1st letter as the SELECT tag does

Jul 27th, 2002 20:20
Jean-Bernard Valentaten, Peter Cinquini,


I'm not sure whether this approach will work, but here's the idea:
What you need is to trap the onKeyUp-Event (which occurs when a key has 
been pressed and released). This would look like this:
<select ... onKeyUp="someKeyHandler();"></select>
Now every time a key is pressed and released the function is called.
The function needs to determine which key has been pressed and writes 
it to the end of a buffer (a simple var containig the keystrokes).
It then needs to check all the option-tags inside the specific select-
block and compare their content (usually the value attribute) with the 
buffer. If an option-tag was found that starts with the buffer-content 
it needs to set it's selected attribute. You'll have to define what it 
does if no match was found.
That should do the trick. I don't think that's it's going to be a piece 
of cake to programm this but it is possible.
What you need to figure out is:
- when is the buffer emtied (I'd say onClick)
- how to determine which key was pressed
HTH,
Jean