By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,712 Members | 2,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,712 IT Pros & Developers. It's quick & easy.

Capture Enter Key...

P: 10
Hello,

I'm developing a website using PHP, Javascript and MySQL.

I have a login form with a couple of textboxes and a login button. What I
want to do is capture the Enter key so that when the user presses Enter, it will behave like tab and throw the onchange event (written for each field).

I have searched the Internet for hours now trying to find out how to do it,
but any methods that I have seen do not work.

Can anyone help me do that?

Regards,
Sourav
Jul 9 '08 #1
Share this Question
Share on Google+
5 Replies


hsriat
Expert 100+
P: 1,654
Expand|Select|Wrap|Line Numbers
  1. document.body.onkeypress = function (event) {
  2.     event = event || window.event;
  3.     if (event.keycode = 13) {
  4.         alert('Enter key pressed');
  5.         return false;
  6.     }
  7.     return true;
  8. }
Jul 9 '08 #2

P: 10
Expand|Select|Wrap|Line Numbers
  1. document.body.onkeypress = function (event) {
  2.     event = event || window.event;
  3.     if (event.keycode = 13) {
  4.         alert('Enter key pressed');
  5.         return false;
  6.     }
  7.     return true;
  8. }
Hello...

Thanks for ur valuable reply...
Jul 9 '08 #3

hsriat
Expert 100+
P: 1,654
Hello...

Thanks for ur valuable reply...
You are welcome. I hope you have manipulated it according to your needs.
Jul 9 '08 #4

P: 2
Hey Folks,

I'm write it using JQuery as follows..

Expand|Select|Wrap|Line Numbers
  1. $(selector).live('keydown', function(e) {
  2.         var key = e.which||e.keyCode;     
  3.         //var key = (window.event) ? e.keyCode : e.which; 
  4.         //var key = (window.event) ? window.event.keyCode : e.which; 
  5.     if (key == 13) {
  6.         alert('Enter key pressed');
  7.         return false;
  8.     }
  9.     return true;
  10. });
Jul 2 '10 #5

P: 2
@hsriat
Here single assignment(=) is used instead of equal of (==), Actually keycode can work but keyCode is actual..
Jul 2 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.