As you are using Bootstrap, the example below uses jQuery.
var ENTER_KEY = 13;
$('textarea').on('keypress', function(event) {
var char = event.which || event.keyCode;
if (char == ENTER_KEY) {
event.preventDefault();
$(this).parent('form').submit();
}
})
I did not put snippet because StackOverflow blocks, but you can see it working in JSFiddle strong> .
If you want to keep the line break when the user presses SHIFT + ENTER you can check with mouveEvent#shiftKey()
that returns true
if shift is pressed: p>
var ENTER_KEY = 13;
$('textarea').on('keypress', function(event){
var char = event.which || event.keyCode;
if(char == ENTER_KEY){
event.preventDefault();
if(event.shiftKey){
$(this).val($(this).val() + '\n'); // shift + enter = Quebra linha
return;
}
$(this).parent('form').submit(); // somente o Enter = Envia o form
}
});
Example online at JSFiddle .
API: