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? 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. 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. 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); 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
Archived
This topic is now archived and is closed to further replies.