Link to home
Start Free TrialLog in
Avatar of glkubs
glkubs

asked on

Is it possible to alter the charCode received during a keypress or keydown events

Can javascript alter the character value received by a keypress event?  keypress can filter out characters by returning true or false, but the question is can it Alter the character returned for display in the textbox?
Avatar of leakim971
leakim971
Flag of Guadeloupe image

No you CAN'T. User need to be the master of its browser, not the hacker behind the screen

But you can :
event.preventDefault();
append an other character of your choice
ASKER CERTIFIED SOLUTION
Avatar of Alex [***Alex140181***]
Alex [***Alex140181***]
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of glkubs
glkubs

ASKER

Alex,

Thank you for an almost perfect solution... I'm using jquery, so for some reason I had to change the evt.cancelBubble to use evt.preventDefault();  Otherwise, I got the original character and the one I was adding!  (simple lower to upper case at the moment).

Thank you... This makes filtering user input easy!
seriously?!? ;-)
input.value += ",";

I had to change the evt.cancelBubble to use evt.preventDefault();

But you can :
event.preventDefault();
append an other character of your choice


Ahem...
But you can :
event.preventDefault();
append an other character of your choice

Ahem...

Btw: You should really provide a little bit more information that might guide the asker to a suitable solution ;-)