Forum Moderators: open

Message Too Old, No Replies

<br> and Textbox values

         

aax123

1:35 pm on Mar 4, 2006 (gmt 0)

10+ Year Member



I need to find a way to allow the user to be able to enter into a textbox a sentence and make it appear as it is written. Currently I have told them they need to enter <br><br> for a new line. Is there a way to not have to make the user enter <br><br> for it to display correctly.

What I mean is when the user submits a paragraph and it is stored in the database if there is no <br><br> in the data when it is displayed on the page there is no line breaks.

I want it to automatically read like this:
This is a test and I
need it to work properly.

But if it isn't stored like this:
This is a test and I<br><br>
need it to work properly.

It looks like this:
This is a test and I need it to work properly.

GaryK

4:21 pm on Mar 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Using the Replace function is one way to solve your dilemma. When the user presses Enter while composing a message an invisible CR (carriage return) and LF (line feed) become part of the message. Those two characters are represented by the constant vbCrLf in most of MS's scripting and programming languages. You need to convert the CR+LF into something most browsers recognize as a line break. So the following code will do the trick. Where you use it is up to you. IMO I prefer to store the message in my database in its raw format because it takes two characters per CR+LF whereas the <br> takes four characters; or six if you use XHTML (<br />).

Response.Write Replace(txtMsg, vbCrLf, "<br>")