phpjayx Posted January 14, 2013 Share Posted January 14, 2013 If I already have a Submit button which send over a username and password. How do I allow the user to press the ENTER key as an alternative to pressing the Submit button? Quote Link to comment https://forums.phpfreaks.com/topic/273118-using-enter-key-to-trigger-a-button-event/ Share on other sites More sharing options...
Jessica Posted January 14, 2013 Share Posted January 14, 2013 If it's an HTML form, that is default functionality. Quote Link to comment https://forums.phpfreaks.com/topic/273118-using-enter-key-to-trigger-a-button-event/#findComment-1405477 Share on other sites More sharing options...
Christian F. Posted January 14, 2013 Share Posted January 14, 2013 Unless you've done something to override the default behaviour, all browsers (I know of) support this out of the box. Quote Link to comment https://forums.phpfreaks.com/topic/273118-using-enter-key-to-trigger-a-button-event/#findComment-1405478 Share on other sites More sharing options...
codefossa Posted January 14, 2013 Share Posted January 14, 2013 Unless you are wanting to remove the submit button, then the two above me are correct. If you do want to remove it and still be able to submit .. Something like this could work. window.document.querySelector("#myFormId").addEventListener("keyup", function(event) { if (event.which == 13) this.submit(); }, false); Quote Link to comment https://forums.phpfreaks.com/topic/273118-using-enter-key-to-trigger-a-button-event/#findComment-1405594 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.