Posted By

ginoplusio on 02/16/10


form event key handler submit listener enter keypress

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


How to send a form by pressing ENTER key

 / Published in: JavaScript


Suppose you have a login form and you want to send the form when user press enter on his keyboard and not only by clicking on the submit button. This can be achieved capturing a specific event when the user is typing. We have to capture the keypress event and listen to trigger an action when the enter key is pressed. Example and code in the link above.

  1. <script type="text/javascript">
  2. function submitonenter(formid,evt,thisObj) {
  3. evt = (evt) ? evt : ((window.event) ? window.event : "")
  4. if (evt) {
  5. // process event here
  6. if ( evt.keyCode==13 || evt.which==13 ) {
  7. thisObj.blur();
  8. document.getElementById(formid).submit();
  9. }
  10. }
  11. }
  12. </script>

Report this snippet  

You need to login to post a comment.