• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1793
  • Last Modified:

How to keep the text from a textarea in the same format inside SQL Database?

Ok,.. this question kinda spans over a couple areas, but since its mainly dealing with SQL, I put it here.

I have an ASP page with a form on it.  On the form is a large textarea for comments.  

On Submit, the textarea, along with the rest of the form fields goes to a ASP handler, which loads it all into a SQL table.

After that, I pull this information down onto another page.  When I pull it down, all the text from the textarea is run together without any formatting.

Is there anyway to send the text from the textara to the SQL Database and back down to the other page, while still retaining its spacing, tabs, and other formatting features?

0
DrinkGreen
Asked:
DrinkGreen
  • 2
  • 2
  • 2
1 Solution
 
LandyJCommented:
You need to translate characters like carriage return (Chr(13)), double spaces, etc into their HTML equivalents.

Double spaces dispaly only as single space (html compacts it), so Replace(text, "  ", "  ")
CR  -- Replace(textarea, Chr(13), "<br")

this should get you started.

hth,
Landy
0
 
LandyJCommented:
Here's a routine I use:

DBField = HTMLEscape(texarea)

  Private Function HTMLEscape(ByVal xField As String) As String
    'Replace these characters with their HTML encoding: &, ', "
    xField = Replace(xField, "&", "&amp;")
    xField = Replace(xField, "'", "&#39;")
    xField = Replace(xField, """", "&quot;")

    'Get these Extended characters
    xField = Replace(xField, Chr(145), "&#39;") 'left single quotation mark to regular single quote
    xField = Replace(xField, Chr(146), "&#39;") 'right single quotation mark to regulare single quote
    xField = Replace(xField, Chr(147), "&quot;") 'left double quotation mark to regular double quote
    xField = Replace(xField, Chr(148), "&quot;") 'right double quotation mark to regular double quote
    xField = Replace(xField, Chr(150), "&ndash;") 'dash the length of 'n' character
    xField = Replace(xField, Chr(151), "&mdash;") 'dash the length of 'm' character
    xField = Replace(xField, Chr(188), "&frac14;") ' 1/4
    xField = Replace(xField, Chr(189), "&frac12;") '1/2
    xField = Replace(xField, Chr(190), "&frac34;") '3/4

    'Return Escaped field
    Return xField
  End Function
0
 
DanRollinsCommented:
Normal display of text on an HTML page exhibits the symptoms you describe.  That is the way web pages are supposed to work.

One possible option is to wrap the data in
      <PRE> ...your data here... </PRE>
tags.  That will make the text be displayed in a fixed-width font and it will preserve line-ends and so-forth... in breifl, it will probably look more like the original text.

-- Dan
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
DrinkGreenAuthor Commented:
So do I put the <PRE> </PRE> tags around the textarea, or inside it.... or do I put it on the page that pulls the text out of the database?
0
 
DanRollinsCommented:
Use it on the page that displays the output.

Odds are, the data in the database is formatted as desired, but it will depend upon what it includes.  If the Textarea contains <table> tages and other major formatting, then the issue will be more complex.  To verify/diagnose that, use Query Analyzer or other tool to examine the data in situ in the database.
0
 
DrinkGreenAuthor Commented:
No, I don't have any <table> tags in it.

That worked great!  Thanks for the tips DR.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now