Last Updated: January 23, 2019
·
1.328K
· 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 ·