-2

The following code i have created is allowing me to capture the numeric values entered by the traditional keyboard number keys.

onkeydown="return (event.keyCode=8 && event.keyCode=144 && (event.keyCode>=48 && event.keyCode<=57));"

But the code is not capturing the key strokes that comes from the number pad located in the modern keyboards.

Appreciate if any one can help me.

Alex K.
  • 171,639
  • 30
  • 264
  • 288
thilim9
  • 227
  • 2
  • 8
  • 17
  • 1
    try `console.log()`ing the event.keyCode to see what is coming in – Greg B Aug 24 '16 at 13:51
  • 1
    That is not valid js; `==` not `=` and how can it be 8 *and* 144? - See [keyCode values for numeric keypad?](http://stackoverflow.com/questions/13196945/keycode-values-for-numeric-keypad) – Alex K. Aug 24 '16 at 13:53
  • numpad keys have different keyCodes than the numbers that appear above the letters. Please google. – ndugger Aug 24 '16 at 13:56

1 Answers1

0

keyCode 8 = backspace

keyCode 144 = num lock

keyCode 48 to 57 = 0 to 9

keyCode 96 to 105 = 0 to 9 in numpad

but for me this is completly wrong :

onkeydown="return (event.keyCode=8 && event.keyCode=144 && (event.keyCode>=48 && event.keyCode<=57));"

maybe something like that :

onkeydown="return ((event.keyCode>=48 && event.keyCode<=57) || (event.keyCode>=96 && event.keyCode<=105));"
MaximeK
  • 2,039
  • 1
  • 10
  • 16
  • Please do not encourage bad questions by replying with bad answers--OP could easily have discovered the different keycodes with the most basic of google searches. – ndugger Aug 24 '16 at 14:00