Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove Hard Returns from javascript

Status
Not open for further replies.

checkai

Programmer
Joined
Jan 17, 2003
Messages
1,629
Location
US
I want to display some TextArea information in a DIV tag...I need to remove the hard returns stored in the DB however to make things show up correctly...

tried this to remove white space, but did not work...any suggestions?

thanks.

Code:
function remove(str){
return str.replace(/^\s+/,"").replace(/\s+$/,"").replace(/\s+/g," ");
}

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Try this:
Code:
function removeLB(str){
   return str.replace(/\r/g,"").replace(/\n/g,"");
}
And if you're wanting them to display as line breaks inside the div then you'll need to apply some HTML tags for the browser to understand:
Code:
function removeLB(str){
   return str.replace(/\r/g,"").replace(/\n/g,"[!]<br />[/!]");
}

-kaht

How much you wanna make a bet I can throw a football over them mountains?
sheepico.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top