I am trying to disable all other characters from being entered in text input.
Since to get the $ you have to press the shift-key and the
Key codes relate only to keys. $ is a character, achieved through two keys, Shift and 4. There is no key code explicitly for $ when using onkeydown
Edit: It was pointed out by Edward that onkeypress uses key combinations, and does have keycode's for combinations. Learn something new every day :)
Here's some code, edited from the onkeydown example provided by the MDN, to detect keypress keycodes.
Here's the fiddle updated to be Firefox-friendly, using help from this S.O. post. The JQuery solution works too, if you swing that way.