Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  152] [ 4]  / answers: 1 / hits: 16082  / 11 Years ago, sun, august 25, 2013, 12:00:00

I am trying to get value of a textarea with line break. When I debug, the value is this way in jquery. the value stored in a variable like this:



test<br>
test<br>
test<br>
In .value of valueOf is: 'test↵test↵test'.


I wonder how can I convert it to n in order to insert line break.. I'm using jquery to get the value and send by ajax to php!


thanks.. :)

Sorry my english..


More From » jquery

 Answers
91

Try this



val=document.getElementById('recommend').value;
val = val.replace(/<brs*/?>/mg,n);


Fiddle http://jsfiddle.net/eSub4/1/



I have put a couple of console.log in fiddle to show you how new line(n) and html line break show up in console and compare it with the text from textarea to see that you are getting new line (n) for text in textarea after using the regex. Keep firebug open to see the output


[#76146] Friday, August 23, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dasias

Total Points: 344
Total Questions: 100
Total Answers: 100

Location: Hong Kong
Member since Tue, Oct 19, 2021
3 Years ago
;