Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I wanna get keyCode when when press on input text
JavaScript
event.keyCode
works fine in IE and Chrome
To work in Firefox I write this
JavaScript
keyCode = event.which || event.keyCode


but it doesn't work too.
any help ?
Posted
Updated 5-Apr-15 2:42am
v2

1 solution

Hi,
Write like this..
JavaScript
function checkKey(evt) {
  var keyID = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
  alert(keyID);
}



Ref this links..

1) JavaScript window.event.keyCode not working in IE, Mozilla FireFox, Chrome, Safari and Opera
2) event.keyCode not working in Firefox
3) Javascript keycodes not working in firefox but works well in chrome
 
Share this answer
 
Comments
Heba Kamel 5-Apr-15 9:41am    
doesn't work
[no name] 5-Apr-15 10:22am    
k,then check the above ref links.
and
ref : check this also
Heba Kamel 6-Apr-15 7:02am    
Hi,
thanks this line
keyCode = event.which || event.keyCode
works fine when I pass event as a parameter to function
Thanks
[no name] 6-Apr-15 7:03am    
Now your problem is solved?
Heba Kamel 6-Apr-15 17:02pm    
yes, thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900