Adding Line Breaks into Text Area using JavaScript | Coding Cluster - using asp.net, c#, mvc 4, iphone, php, ios, javascript, in asp.net mvc 3 & more
 

Adding Line Breaks into Text Area using JavaScript

Monday

Textarea - output not showing linebreaks:
        Whitespace in HTML output, including many white-space characters in a row,is displayed in HTML pages as a single  ordinary space. And a line break also considered as whitespace.
If you want to display text that includes linebreaks in HTML so that the linebreaks show, you can do the following ways
  •  Put the text in between <pre> and </pre> tags.
  • (Use your server/client side language to convert the line breaks into <br /> tags.

For example,
Adding Line Breaks into Text Area using JavaScript:

var strAddress= document.forms[0].txt.value;
text = strAddress.replace(/\n\r?/g, '<br />');

Adding Line Breaks into Text Area using PHP:

$strAddress = str_replace("<br>", "\n", $strAddress);


Please share this post if it's useful to you. Thanks!.

0 comments:

Post a Comment

Share your thoughts here...

 
 
 

RECENT POSTS

Boost

 
Blogger Widgets