Using numeric values to select item from a dropdown box with JavaScript
Posted
by
Shyam
on Stack Overflow
See other posts from Stack Overflow
or by Shyam
Published on 2011-01-01T15:51:26Z
Indexed on
2011/01/01
15:53 UTC
Read the original article
Hit count: 234
Hi,
I have a multitude of dropdown boxes within my webpage. One of these dropdown boxes is used for a single selected value out of a list of options.
<SELECT id="Box0" name="">
<OPTION value="0">none</OPTION>
<OPTION value="1">first</OPTION>
<OPTION value="2">second</OPTION>
</SELECT>
How can I add an event to this section, so when it is in focus, I could use numeric keys like 1,2.. to select an option instead of using the mouse or arrow keys for selecting an option? For clarification: if I press "1" on my keyboard, the selected value would become "first", with "2" the selected value becomes "second".
I choose not to use a library/framework such as JQuery/Mootools.
Thanks,
© Stack Overflow or respective owner