In the following script, when del key is pressed it returns 46 instead of 127, which is the ASCII code of del key.
function countLength(evt) {
var inp = (evt.which) ? evt.which : event.keyCode;
alert (inp);
return true;
}
Values returned by
event.keyCodeare not ASCII codes. They just indicate which key was pressed on the keyboard. For example pressing0-key on the topmost row of the keyboard returns 48, but pressing0on numberblock returns 96.To convert keycodes to ASCII , you have to use some kind of an array containing corresponding values. In this task you have to check all other keys pressed simultaneously, like
shiftKeyandaltKeyto have correct results.