Here is the javascript function that handle the event:
01 02 03 04 05 06 07 08 09 10 11 12 | <script type="text/javascript"> function submitonenter(formid,evt,thisObj) { evt = (evt) ? evt : ((window.event) ? window.event : "") if (evt) { // process event here if ( evt.keyCode==13 || evt.which==13 ) { thisObj.blur(); document.getElementById(formid).submit(); } } }</script> |
This is the html form with the “onkeypress” listener:
1 2 3 4 5 | <form id='formlogin' action='file.php' method='post'> <input type='text' name='username' /> <input name='pass' type='password' onkeypress="submitonenter('formlogin',event,this)" /> <input type='submit' value='login'/></form> |
Read full article from How to capture enter key pressed in a form (JavaScript) - Barattalo
No comments:
Post a Comment