Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    215
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Need carriage return input automatically

    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,

    Parallon

  • #2
    Regular Coder
    Join Date
    Jan 2005
    Posts
    155
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    Code:
    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.

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    215
    Thanks
    14
    Thanked 0 Times in 0 Posts
    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:

    Code:
    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:

    Code:
    Here is part 1.
    Here is part 2.
    
    Here is part 3.
    Here is what I get when I view source:

    Code:
    <td bordercolor="#999999">Here is part 1.
    Here is part 2.
    <br />
    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?

    Thanks again,

    Parallon

  • #4
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    While chr(10) & chr(13) is correct (chr(10) = Carriage Return and chr(13) = New Line Feed), try doing a :

    Code:
    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.

  • #5
    Regular Coder
    Join Date
    May 2005
    Posts
    215
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Sooooo awesome. Thank you so very much. Worked like a charm.

    Parallon

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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.
    Code:
    <td bordercolor="#999999">
    <pre><%=rs("memo_field")%></pre>
    </td>
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #7
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •