Cooking with JavaScript & DHTML
Subject:   numbers as option text?
Date:   2004-01-16 11:02:13
From:   dannyg1
Response to: numbers as option text?

With the onkeydown event, we're dealing with key codes, not character codes. The key codes for the numeric keypad are different from the key codes across the top of the keyboard.
But there is an simple relationship between the two sets, and the way to account for it is to insert a small corrector statement in the typeAhead() function after the line that reads: var charCode = evt.keyCode. Here's the new code to add:

// correct for NumPad digits
if (charCode >= 96 && charCode <=105) {
charCode = charCode - 48;

That should let the numeric keypad (and top row numbers) work with option values consisting of numerals.

In hindsight, I'd word some of the comments in the article code differently to prevent giving the impression the event is working with character codes.

Main Topics Oldest First

Showing messages 1 through 1 of 1.

  • numbers as option text?
    2004-10-11 07:50:13  wolffy [View]

    Thank you, for this code. I have been look for code like this for some time. And this is the fastest. I added your updated code, so the tab and numeric look ahead is working fine. but when I go over a number that is not found the last digit resets the look ahead function and starts all over with the last number. I am using it to type ahead through 10,200 numbers. It works fine with 9168 numbers, but If I ad one more to the select object the nearest fails. Can you help?