Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

catching ascii key codes in javascrip

 
Greg machamer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've written some javascript to only allow numbers and letters to be inputed into text fields on the screen.

I've also got the code making it over write whats on the screen and not inserting the values. But when I type in a lower case a or an upper case A I'm always getting the ascii code for the upper case A.

If I press any number on the number pad I'm getting the ascii code for lowercase letters.

When I then try to insert the letter that was entered by using the ascii code it overwrites the current possition with the wrong value.

Any ideas? Besides removing or rewriting the over write feature?

 
Greg machamer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I seem to have come up with a solution. Instead of returning false inside of the stopRKey function and doing some replacing of characters, which seems to have been the problem. I'm removing the next character and then letting the current key pressed go through (of course both of these are only if the keycode is correct)

That way I don't have to call the fromCharCode function which was not returning the correct character.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you also played with onkeypress and see what happens?

eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic