Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Submit a form on Command+Enter when in a textarea field.
jQuery(function($) {
// add a handler for form submit (makes an AJAX call)
$(document).on('submit', 'form.my-class', myFormSubmitHandler);
// submit form on command + enter if in a textarea
$(document).on('keydown', 'body', function(e) {
if (!(e.keyCode == 13 && e.metaKey)) return;
var $target = $(e.target);
if ($target.is('textarea')) {
$target.closest('form').submit();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.