Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everyone i tried the keypress event for enter button that is working fine in IE and firefox
but not in chrome
JavaScript
$('.div').bind('keypress', function (e) {
       if (e.keyCode == 13) {
           alert("Enter prssed");
       }
   });

Please help me in this
Posted
Updated 8-Sep-16 0:01am
Comments
ravithejag 25-Jun-13 8:30am    
I also tried keydown instead of keypress then also its not working in chrome
Ahmed Bensaid 25-Jun-13 8:45am    
I think, you have to attach the keypress event to a focusable form element ;)
Kalpesh Kumar Joshi 25-Jun-13 8:47am    
Try this:
http://stackoverflow.com/questions/6311290/keypress-event-not-working-in-ie-and-chrome-
but-working-in-ff
Kalpesh Kumar Joshi 25-Jun-13 9:32am    
Hi Ravi,
I tried this code and found that in chrome HTML button tag not get focused or it lost focus after any event call, if you call a focus set method before keydown/keypress event then it works fine in chrome, also i tried with input type and it work fine in chrome with "keydown" or "keypress" event. Hope you find it relevant.
Member 12727231 8-Sep-16 6:01am    
Keypress event not working in Chrome
Rate:


See more: ASP.NET Javascript jQuery
Hello everyone i tried the keypress event for enter button that is working fine in IE and firefox
but not in chrome
Hide Copy Code
$('.div').bind('keypress', function (e) {
if (e.keyCode == 13) {
alert("Enter prssed");
}
});
Please help me in this
Permalink Posted 25-Jun-13 7:30am
ravithejag3.8K
Updated 32 secs ago

Hello Ravi,

I have setup a demo at JSFiddle.Net[^], which even works in chrome. Since you have not shared the HTML markup, I have taken liberty to use my own markup, which may be different than your's. Please feel free to fiddle with it.

In your case if you want to bind to a particular button then you may want to change your selector to an id based selector ('#' + CONTROL_ID).

Regards,
 
Share this answer
 
Comments
Member 12727231 8-Sep-16 6:01am    
Keypress event not working in Chrome
Rate:


See more: ASP.NET Javascript jQuery
Hello everyone i tried the keypress event for enter button that is working fine in IE and firefox
but not in chrome
Hide Copy Code
$('.div').bind('keypress', function (e) {
if (e.keyCode == 13) {
alert("Enter prssed");
}
});
Please help me in this
Permalink Posted 25-Jun-13 7:30am
ravithejag3.8K
Updated 32 secs ago
Prasad Khandekar 21-Feb-17 9:36am    
Hi,

The JSFiddle demo I have setup appears to be working in Chrome. I have tested with 56.0.2924.87.

Regards,
ravithejag 23-Feb-17 22:52pm    
Yes Prasad its working as expected in Chrome.Thnaks
C#
Hello Ravi,

I have setup a demo at JSFiddle.Net[^], which even works in chrome. Since you have not shared the HTML markup, I have taken liberty to use my own markup, which may be different than your's. Please feel free to fiddle with it. 

In your case if you want to bind to a particular button then you may want to change your selector to an id based selector ('#' + CONTROL_ID).

Regards,
  Permalink    Posted 25-Jun-13 7:42am
 
Share this answer
 
Comments
Member 12727231 8-Sep-16 6:01am    
Keypress event not working in Chrome
Rate:


See more: ASP.NET Javascript jQuery
Hello everyone i tried the keypress event for enter button that is working fine in IE and firefox
but not in chrome
Hide Copy Code
$('.div').bind('keypress', function (e) {
if (e.keyCode == 13) {
alert("Enter prssed");
}
});
Please help me in this
Permalink Posted 25-Jun-13 7:30am
ravithejag3.8K
Updated 32 secs ago
C#
Keypress event not working in Chrome
Rate:	
 
  	
See more: ASP.NET Javascript jQuery
Hello everyone i tried the keypress event for enter button that is working fine in IE and firefox
but not in chrome 
Hide   Copy Code
$('.div').bind('keypress', function (e) {
       if (e.keyCode == 13) {
           alert("Enter prssed");
       }
   });
Please help me in this
  Permalink         Posted 25-Jun-13 7:30am
ravithejag3.8K
Updated 32 secs ago
 
Share this answer
 

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