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

Call function if enter key is pressed

P: 14

I have a text control in my form. When I press a Enter key in this control , it should called another javascript function, but it is not doing so instead it is triggering "Submit" button event. Can you please help.

I have wrote a onkeypress function as follows:

<input type="text" id="txt1" style="width:300px" MaxLength="50" onkeypress="javascript:testEnter()"/>

function testEnter() {

Thanks in advacne
Apurva G
Jul 29 '08 #1
Share this Question
Share on Google+
1 Reply

P: 13,262
Either swallow the enter by setting it to null
Expand|Select|Wrap|Line Numbers
  1. if(event.keyCode==13){
  2.         event.keyCode = null;
  3.         //call function
  4.     }
or better set it to tab which I think will be
Expand|Select|Wrap|Line Numbers
  1. event.keyCode = 9;
Jul 29 '08 #2

Post your reply

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