In an input box if you press RETURN/ENTER you submit the form. In a textarea pressing RETURN produces a line-break. How do you make a that on RETURN keydown instead of producing a line-break submits the form and in SHIFT+RETURN produces the line-break? (Like fb and other sites do)
Is there some way to do it with just HTML? If not how can it be done with JS?
This is what I am trying right now:
$('#conversationForm textarea').keydown(function(e) {
e = e || event;
if(e.keyCode == 13 && !e.shiftKey) {
$("#conversationForm").submit();
return false;
}
});
However when I haven’t been able to prevent the line-break from happening. (If you press RETURN the line break is visible before submitting.)
Using jQuery, and similar to the other answers, but including your request to make shift not submit but just do a line break
Here if shift is pressed, it won’t submit and just give you a line-break.