Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add new line character to textarea instead of submitting form

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.

like image 741
Khizar Avatar asked Dec 24 '12 10:12

Khizar


People also ask

How do you add a new line in textarea?

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!

How do I add special characters to textarea?

Inside a textarea , you need to convert the following characters into their HTML entities: & => &amp; > => &gt; < => &lt; That way, &#5 would become &amp;#5 . Visually, to the user, it would remain &#5 .

Which character defines a new line in the textarea?

Talking specifically about textareas in web forms, for all textareas, on all platforms, \r\n will work.

How do you add a new line character in HTML?

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.


1 Answers

$('textarea').keypress(function(event) {
   if (event.which == 13) {
      event.stopPropagation();
   }
});​

JSFiddle Demo

like image 168
Muhammad Talha Akbar Avatar answered Oct 05 '22 15:10

Muhammad Talha Akbar