Jump to content
Sign in to follow this  
raghunathmitte

On Pressing Enter Key

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)

Share this post


Link to post
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?

Share this post


Link to post
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;  } 		 }

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...