Last Updated: January 23, 2019
·
1.783K
· idered

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 :)

1 Response
Add your 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
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