views:

461

answers:

2

I have a form in asp that does some javascript error checking them shows a preview of the form information before the user submits it to our database. To enable light formatting before submission we replace all of the line breaks with tags.

<textarea name="DATA_Description" ROWS=30 wrap=on cols="30"><%=DATA_Description%></textarea>

Replacing line break with

<%=replace(DATA_Description,vbcr,"<BR>")%>

This works perfectly in all browsers with the exception of Chrome. Chrome is inserting an extra line break at the end of each line in the textarea. We use the text in multiple width areas with multiple font styles so i need the line breaks to only occur when the user actually enters a hard return...

Any suggestions?

+1  A: 

You're only replacing carriage returns and not linefeeds, which are being displayed in the textarea. I'd be unsurprised if Chrome on Windows used CRLF instead of simply LF, and I wouldn't expect CR-only.

Anonymous
A: 

I've always used vbcrlf instead of vbcr when I took data from a textarea that was stored in a database and wanted to show it as html instead of back in a textarea (using replace just like you).

I never tested what would happen if the os I used was Linux or Mac which both use just LF instead of CRLF (didn't have to worry about Mac and Linux support back then). And now that I think about it, I wonder if using CRLF or LF is something that's a part of the HTML spec and is the same across all operation systems for any textarea? Hmmm.

tooshel