Re: [jQuery] Re: What is the event when a user presses the enter key anywhere on the page?
$(document).keypress(function(e) { if(e.ctrlKey && e.which == 13) { $('#myForm').submit(); } }); or $('#myForm').keypress(function(e) { if(e.ctrlKey && e.which == 13) { $(this).submit(); } }); - Richard On Thu, Dec 17, 2009 at 7:40 PM, Andre Polykanine wrote: > Hello Mike and all, > > Sorry, I also have a question about keypresses. > I need a form to be submitted by pressing Ctrl+Enter. How do I manage > to do that? > Thanks! > > -- > With best regards from Ukraine, > Andre > Skype: Francophile; Wlm&MSN: arthaelon @ yandex.ru; Jabber: arthaelon @ > jabber.org > Yahoo! messenger: andre.polykanine; ICQ: 191749952 > Twitter: m_elensule > > - Original message - > From: Mean Mike > To: jQuery (English) > Date: Thursday, December 17, 2009, 9:06:36 PM > Subject: [jQuery] Re: What is the event when a user presses the enter key > anywhere on the page? > > keypress > >$(document).keypress(function(e) { >if ((e.which && e.which == 13) || > (e.keyCode &&e.keyCode == 13)) > { >// do something >} >}); > mean mike > On Dec 17, 2:03 pm, "laredotorn...@zipmail.com" > wrote: > > Hi, > > > > I would like to capture the event of pressing enter anywhere on the > > page, even if the focus of the mouse cursor is not on a text field. > > What event/element am I looking at? > > > > Thanks, - Dave > >
Re: [jQuery] Re: What is the event when a user presses the enter key anywhere on the page?
Hello Mike and all, Sorry, I also have a question about keypresses. I need a form to be submitted by pressing Ctrl+Enter. How do I manage to do that? Thanks! -- With best regards from Ukraine, Andre Skype: Francophile; Wlm&MSN: arthaelon @ yandex.ru; Jabber: arthaelon @ jabber.org Yahoo! messenger: andre.polykanine; ICQ: 191749952 Twitter: m_elensule - Original message - From: Mean Mike To: jQuery (English) Date: Thursday, December 17, 2009, 9:06:36 PM Subject: [jQuery] Re: What is the event when a user presses the enter key anywhere on the page? keypress $(document).keypress(function(e) { if ((e.which && e.which == 13) || (e.keyCode &&e.keyCode == 13)) { // do something } }); mean mike On Dec 17, 2:03 pm, "laredotorn...@zipmail.com" wrote: > Hi, > > I would like to capture the event of pressing enter anywhere on the > page, even if the focus of the mouse cursor is not on a text field. > What event/element am I looking at? > > Thanks, - Dave
Re: [jQuery] Re: What is the event when a user presses the enter key anywhere on the page?
Good tip, thanks, Mike. A couple of suggestions... First, you could simplify that if test to: if( e.which == 13 || e.keyCode == 13 ) That would do exactly the same thing in all cases as the original code. But you can simplify it even more. jQuery cleans up the properties of the event object so you don't have to make the browser-dependent tests for both 'which' and 'keyCode'. You can just use 'which' in all browsers: if( e.which == 13 ) -Mike On Thu, Dec 17, 2009 at 11:06 AM, Mean Mike wrote: > keypress > >$(document).keypress(function(e) { >if ((e.which && e.which == 13) || > (e.keyCode &&e.keyCode == 13)) > { >// do something >} >}); > mean mike > On Dec 17, 2:03 pm, "laredotorn...@zipmail.com" > wrote: > > Hi, > > > > I would like to capture the event of pressing enter anywhere on the > > page, even if the focus of the mouse cursor is not on a text field. > > What event/element am I looking at? > > > > Thanks, - Dave >