||When a user is entering text into a TEXTAREA (multi-line text box) control, the carriage returns are not displayed when you view the user's inputted text through a Web page. For example, create an ASP page that has a form with a TEAXTAREA:|
<FORM METHOD=POST ACTION="SomeOtherPage.asp">
Enter some text:<BR>
<TEXTAREA NAME=MyTextBox COLS=40 ROWS=5 WRAP=virtual></TEXTAREA>
SomeOtherPage.asp (where the form sends the user when the above form is submitted), output the value of the TEXTAREA:
Now, if the user entered some text into the TEXTAREA that contained line breaks, like:
These line breaks won't appear when the value of the TEXTAREA is displayed in
SomeOtherPage.asp. You'll see:
This is because when a user enters a carraige return in the TEXTAREA, a simple
vbCrLf (or carraige return) is entered. Carraige returns are skipped over when parsing HTML... If you want to force a linebreak in HTML, you must use the <BR> tag. Therefore, to maintain the line breaks entered by the user in the TEXTAREA, you must first replace all the carraige returns (
vbCrLf) with <BR> tags. You can use the
Replace function to do this!
SomeOtherPage.asp, to maintain the formatting, you'd want to do:
Response.Write Replace(Request("MyTextBox"), vbCrLf, "<BR>")
Note that the above snippet of code simply says, "Hey, where are the
vbCrLf's in the user's TEXTBOX entry? Wherever you find them, replace them with <BR>! Thanks!" And with that simple line of code, we've maintained line breaks in a TEXTAREA! Neat, eh?
For more information on the
Replace function, be sure to read the technical docs.