8

I have a very simple HTML form, only containing a submit button and a textarea. Is there an easy way to use a hotkey to submit this form, as an alternative to pressing the button?

Thanks in advance :-)

Chris
  • 2,905
  • 5
  • 29
  • 30

3 Answers3

5

Submit buttons can have accesskeys, but there are drawbacks. Users would probably be better off just hitting the tab key to focus the submit button, and then pressing enter.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • This is what I'm looking for as the website isn't aimed toward the greater public so the browser difference in handling accesskeys is no problem :-) – Chris Sep 01 '10 at 13:19
  • @MojtabaRezaeian — Works in Firefox 64.0 when I test it. – Quentin Jan 07 '19 at 17:16
2

Here is the jQuery method for adding a keypress listener to your button (by specifying the ID)... you can also do it on your page by changing "YourID" to "document" (without quotes, since document is a page element. I know keypress has been mentioned, figured it would be easier for others to have code here, and not have to move elsewhere.

$("#YourID").keypress(function (e) {
   var code = (e.keyCode ? e.keyCode : e.which); // grabs keycode pressed
   if (code == 13) {  // Code 13 is enter
        searchUPC();
   }
});
Sean Haddy
  • 1,630
  • 1
  • 16
  • 25
2

you can use the "keyDown", "keyPress" events if you use a JS library (JQUERY or MOOTOOLS).. you can program your own Ctrl+S to submit.

On JQuery see this http://api.jquery.com/keypress/

On Mootools see this http://mootorial.com/wiki/mootorial/03-native/05-event

pleasedontbelong
  • 19,542
  • 12
  • 53
  • 77
  • Ctrl+S (in Firefox for Windows at least) usually means "Save this page". Messing with user expectations is usually not a good idea. – Quentin Sep 01 '10 at 13:18