How do I trigger something when the cursor is within TEXTAREA and Ctrl+Enter is pressed? Using jQuery. Thanks
This can be extended to a simple-but-flexible JQuery plugin as in:
$.fn.enterKey = function (fnc, mod) {
return this.each(function () {
$(this).keypress(function (ev) {
var keycode = (ev.keyCode ? ev.keyCode : ev.which);
if ((keycode == '13' || keycode == '10') && (!mod || ev[mod + 'Key'])) {
fnc.call(this, ev);
}
})
})
}
Thus
$('textarea').enterKey(function() {$(this).closest('form').submit(); }, 'ctrl')
should submit a form when the user presses ctrl-enter with focus on that form's textarea.
(With thanks to https://stackoverflow.com/a/9964945/1017546)