Click to See Complete Forum and Search --> : keys and their ascii codes


___
07-14-2006, 03:03 PM
I am trying to show a key typed next to its ascii code like this:

function f()
{alert(event.keyCode.toString()+','+String.fromCharCode(event.keyCode))}

It gets called like <input name="a" type="text" onKeyUp="f();">

Digits from the top of the keyboard work like I expect but other characters do not. Here are some examples.
1) type in b and the alert box says 66,B insead of 98,b
2) type in - and the alert box says 189,1/2 instead of 45,-
3) type in . and the alert box says 190,3/4 instead of 46,.

What am I doing wrong?

asfman
07-14-2006, 09:37 PM
<script>
function f()
{alert(event.keyCode.toString()+','+String.fromCharCode(event.keyCode))}

</script>
It gets called like <input name="a" type="text" onkeypress="f();">
you should use onkeypress event

asfman
07-14-2006, 09:41 PM
because onkeyup not support lowercase letters,but onkeypress surport

___
07-15-2006, 10:47 AM
Thankyou very much.