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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression

Status
Not open for further replies.

SeAL

Programmer
Mar 15, 2001
139
FR
Hi peeps,

I would like to find a way to replace all line breaks of a textarea by &quot;<br>&quot; but this doesn't work with multiple lien breaks.

I use this :

myHtmlMessage = myTempMessage.replace(/[\f\n\r]/g,&quot;<br>&quot;);

Please, need some help !
 
Hi seAl,

I got the regExp you defined there to work fine.

heres the code i used
Code:
<html>
<head>
	<title>Untitled</title>
</head>
<script type=&quot;text/javascript&quot;>
<!--//

function test(){
myTempMessage = document.forms[0].elements[0].value;
alert(myTempMessage);
myHtmlMessage = myTempMessage.replace(/[\f\n\r]/g,&quot;<br>&quot;);
alert(myHtmlMessage);
}
//-->
</script>
<body>
<form>
<textarea name=&quot;text&quot;></textarea>
<input type=&quot;button&quot; value=&quot;fad&quot; onclick=&quot;test(); return false&quot;>
</form>


</body>
</html>
i called the function from an onclick on a form button. the output html message contains two <br> tags between each line from the textarea (one for the newline character and one for the carriage return).

dunno if it will but hope it helps

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top