Jump to content

On Pressing Enter Key


raghunathmitte
 Share

Recommended Posts

I have a form in which an input text box is given for giving input. and a button is provided in it, when i click the button a javascript code is executed and results are displayed, now can any one help me out how to execute the javascript code when enter key is pressed(i.e. the button should be clicked when enter is pressed)

Link to comment
Share on other sites

I have a form in which an input text box is given for giving input. and a button is provided in it, when i click the button a javascript code is executed and results are displayed, now can any one help me out how to execute the javascript code when enter key is pressed(i.e. the button should be clicked when enter is pressed)
Have you tried the onkeypress event?By the way, what event are you using now to execute the javascript code when the button is clicked?
Link to comment
Share on other sites

firefox "clicks" a button when enter is pressed on a focus button.here is a simple way to dupe the click for enter key on same element:where input is the element object you want to bind.

input.onkeyup = function (e) {   if(!e){ e = window.event; }  if (e.keyCode==13 ){  input.onclick() ; return true;  } 		 }

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...