Skip to content

Instantly share code, notes, and snippets.

@brandonhilkert
Created June 22, 2011 02:16
Show Gist options
  • Save brandonhilkert/1039388 to your computer and use it in GitHub Desktop.
Save brandonhilkert/1039388 to your computer and use it in GitHub Desktop.
Submit text in textarea with "Enter"
// Function that allows a textarea to use the enter
// key to submit the associated form
$.fn.submitTextArea = function() {
return this.each(function() {
$(this).keypress(function(e){
if (e.keyCode == 13 && !e.shiftKey) {
e.preventDefault();
$(this).closest('form').submit();
}
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment