I have a form with a text area and hitting the enter key submits my form. How can I make it to add a new line character instead of a form submit.
To add line breaks to a textarea, use the addition (+) operator and add the \r\n string at the place where you want to add a line break, e.g. 'line one' + '\r\n' + 'line two' . The combination of the \r and \n characters is used as a newline character. Here is the HTML for the examples in this article. Copied!
Inside a textarea , you need to convert the following characters into their HTML entities: & => & > => > < => < That way,  would become &#5 . Visually, to the user, it would remain  .
Talking specifically about textareas in web forms, for all textareas, on all platforms, \r\n will work.
To add a line break to your HTML code, you use the <br> tag. The <br> tag does not have an end tag. You can also add additional lines between paragraphs by using the <br> tags. Each <br> tag you enter creates another blank line.
$('textarea').keypress(function(event) {
if (event.which == 13) {
event.stopPropagation();
}
});
JSFiddle Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With