Send forms using Ctrl + Enter
Many times, after I finish writting my comment or post, I press Ctrl + Enter and ... nothing. That's too bad, form should be sent after I press that shortcut but nothing happens. Here's a snippet which will help you add this function for your forms:
var isCtrl = false;
$('textarea, input').keyup(function(e) {
if (e.which == 17) isCtrl = false;
}).keydown(function(e) {
if (e.which == 17) isCtrl = true;
if (e.which == 13 && isCtrl === true) {
$(this).closest('form').submit();
return false;
}
});
Orginal post on my blog
Upvote on HN coz I want to see this function on much more websites :)
Written by Kasper Mikiewicz
Related protips
1 Response
I wish this was mandatory for all websites. (as I write this I notice that Coderwall doesn't have it.)
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Snippet
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#