Forum Moderators: open

Message Too Old, No Replies

Preserving return characters.

         

TheSeoGuy

5:22 pm on Dec 6, 2004 (gmt 0)

10+ Year Member



I have a standard html text field set to accept multiple lines of text. I then take this text and save it to a database to be displayed in another page called display.asp. The problem is that when the user types data into the text field and wants to start a new paragraph by pressing the return key on the keyboard, these returns do not get shown in my final output on the display.asp page.

If I use the javascript function indexOf(“\n”), it returns the character number that matches the location of where the return key was pressed. Having discovered this, I tried swapping out the \n for <br> but cannot seem to get it to work correctly.

Has anyone found a way to work around this?

Thanks in advance!

CaseyRyan

5:51 pm on Dec 6, 2004 (gmt 0)

10+ Year Member



You can do the formatting with ASP code. You're going to search for the ASCII Carriage Return (Chr(13)) and Line Feed (Chr(10)) values which are equivalent to the return key. You'll replace them with the <BR> tag.

You would put the following into your display.asp.


<%
Dim vbCrLf
Dim myText
vbCrLf = Chr(13)&Chr(10)
myText = Trim(rs("storedText")&"")
myText = Replace(myText,vbCrLf,"<BR>")
Response.Write(myText)
%>

-=casey=-

TheSeoGuy

6:15 pm on Dec 6, 2004 (gmt 0)

10+ Year Member



Casey,

Thank you for your help! That is exactly what I was looking for.

Works perfectly!

Thanks again.