theniteowl
Programmer
Hi All.
Dilema:
I need to trap the control key in an input field so that people can NOT paste into it.
I also need to be able to detect which character was entered so that I can test it for validity elsewhere.
The problem:
In IE the onkeypress event can trap the ctrl key but NOT when focus is in an input field.
The onkeydown event WILL trap the ctrl key in an input field but the value it returns is always the constant regardless of case. So the keyCode value comes out as 65 no matter if you pressed a capital or lower case A.
The onkeypress event returns the correct value but cannot trap the ctrl key so I am trying to find a workaround.
Interestingly, if you use onkeydown it will return 65 no matter if it is upper or lower case A but it actually inserts the correct case into the input field. So the value MUST be there somewhere but is it accessible from code other than letting the keypress complete and then reading the text field to get the character?
Anybody?
I always get the frustrating problems.
Stamp out, eliminate and abolish redundancy!
Dilema:
I need to trap the control key in an input field so that people can NOT paste into it.
I also need to be able to detect which character was entered so that I can test it for validity elsewhere.
The problem:
In IE the onkeypress event can trap the ctrl key but NOT when focus is in an input field.
The onkeydown event WILL trap the ctrl key in an input field but the value it returns is always the constant regardless of case. So the keyCode value comes out as 65 no matter if you pressed a capital or lower case A.
The onkeypress event returns the correct value but cannot trap the ctrl key so I am trying to find a workaround.
Interestingly, if you use onkeydown it will return 65 no matter if it is upper or lower case A but it actually inserts the correct case into the input field. So the value MUST be there somewhere but is it accessible from code other than letting the keypress complete and then reading the text field to get the character?
Anybody?
I always get the frustrating problems.

Stamp out, eliminate and abolish redundancy!