Thursday, October 18, 2012

Replacing Enter Key/Carraige return with br tag

When data is saved from a textArea and the data contains carriage returns(Enter key) then if the data is displayed in a text area in another form it will display properly.

However, if you try and display the same text/data as a normal html it will display it but will not consider the carriage returns and all the data will be displayed in a single line.

This can be achieved by:
var data=//get data from the text area
data=data.replace(/\r\n|\r|\n/g,"<br /> ");

now this data can be displayed as html

No comments:

Post a Comment