05-21-2007, 10:03 PM
Hello all. I have been looking all over for an answer for this, but not sure if I am using the correct keywords. Basically what I am trying to do is allow a user to enter descriptions in a memo field and every time they hit the "enter" button on the keyboard, it will automatically enter a carriage return before being sent to my Access database. Can someone lead me in the right direction? I hope this makes sense.
Thanks in advance,
05-21-2007, 10:16 PM
it should already be doing that if this a < textarea > box. if you're talking that it's not displaying on an ASP page correctly, you need to run a replace when displaying it. something like this:
response.Write(replace(rs("memo_field"), chr(10) & chr(13), "<br />")
if you're displaying back in the < textarea> box, you don't need the replace. It will insert the original line feeds.
05-21-2007, 10:50 PM
Thank you for the quick reply. That actually worked pretty good, although I noticed something funny. When I output the data to a table cell, it doesn't seem to recognize the first carriage return but if I output to a text box it does. In other words if I type a line and hit the carriage return once, then type a second line and hit return twice, and then typed a third line, the result in the table cell would be like the following:
Here is part 1. Here is part 2. (seems to add a space to the end of each one)
Here is part 3.
But the results in a text box would be:
Here is part 1.
Here is part 2.
Here is part 3.
Here is what I get when I view source:
<td bordercolor="#999999">Here is part 1.
Here is part 2.
Here is part 3.</td>
So, to get it to work properly in a cell, I have to hit "Enter" one extra time. Does this make any sense?
05-21-2007, 11:26 PM
While chr(10) & chr(13) is correct (chr(10) = Carriage Return and chr(13) = New Line Feed), try doing a :
response.Write(replace(rs("memo_field"), vbCrLf, "<br />")
which is almost the same thing, but Access (and ASP) interpret it a little differently than just 10&13.
vbCrLf = Visual Basic Carriage Return and Line Feed.
05-21-2007, 11:31 PM
Sooooo awesome. Thank you so very much. Worked like a charm.
05-22-2007, 09:00 PM
You can also do it even without the replace function by putting the text inside the <pre> tag. This tag preserves all the whitespaces - spaces, tabs, and newlines.
05-26-2007, 01:34 AM
Yea that replace function is pretty useless. (by the way there are vbNewLine, vbCR, vbLF and vbCRLF if you need them, you don't need to use chr(10) etc)
Your data was getting inserted into the database with all the line breaks, but as you probably know, html won't display the line breaks. You need to either replace them with a <br /> or put the whole thing in <pre>..</pre> on the way out of the database but you don't need to do anything to the data on the way into the database (well I suppose you could replace for <br /> on the way in if it is going to be posted once, displayed a lot and never edited)
You can also use Server.HTMLEncode("..."). If I remember correctly automatically replaces the whole thing to show up properly. Even if the text contains HTML and line breaks etc, it will safely display it without interfering with the html of the page.