Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tough onkeypress onkeydown problem

Status
Not open for further replies.

theniteowl

Programmer
Joined
May 24, 2005
Messages
1,975
Location
US
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!
 
Sometimes there is another solution. Can I ask why you do not want the user to Cntl-V into the field?

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Because I am trapping every keypress and testing individual characters entered into the field and responding to them before they write to the box. If a ctrl-v is used it counts as a single keypress pasting an unknown number of characters into the field.

The only other ways I can see are testing the data AFTER it get's written to the field and then removing illegal characters which you can see happen in the browser and is just not a clean solution.


Stamp out, eliminate and abolish redundancy!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top