Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

coding to include hard returns entered into textareas in form results. 1

Status
Not open for further replies.

cdck

Programmer
Nov 25, 2003
281
US
I have a form with a text area, and the information from this form is processed through VBScript and then entered into an Access database. Currently, if a user hits enter while in the text box they move to a new line in the box. However, when this field is processed, the result looks like they did not hit enter at all. How can I evaluate the string, find hard returns, and replace them with <p> before storing them in the database?

Cheryl dc Kern
 
You will need to make the value of the textarea into a regular expression.

Then do a global replace on \r and \n with <br />, assuming you are wanting this textarea content to appear as html code.


This is the VBScript code that will do that for you. You can put this code in a function or do what you want with it.

Code:
dim textAreaValue, regExp

Set textAreaValue = thisTextarea.value
Set regExp = New RegExp

regExp.Global = True
regExp.Pattern = "\r|\n"

str1 = regExp.Replace(str1, "<br />");

With textarea defined as:
Code:
<textarea name="thisTextarea">dlkfjsldkjsdlkfjs</textarea>

[monkey][snake] <.
 
Ok, I got pretty excited when I saw this, but then realized that I am confused. I apologize for needing some clarification.

Currently the process run on the result from that field looks like this:

Notes = request.Form("Notes")
Notes = Replace(Notes, "'", "''")
Notes = Replace(Notes, Chr(34), "''''")
If Notes = "special notes/attachments" Then Notes = NULL End If

How do I integrate your solution with this? What really throws me off is the assignation of request.Form("Notes") as the value for Notes, I'm not sure how to pull your code into that. The replacements can all be done after the new code, I'm sure.

Cheryl dc Kern
 
Based on what I see, you would just add after this statement, Notes = Replace(Notes, Chr(34), "''''"), this code:

Code:
Notes = Replace(Notes, /\r|\n/g, "<br />")





[monkey][snake] <.
 
I got this error:

Microsoft VBScript compilation error '800a03ea'

Syntax error

/PR/process/PRStartStep1process.asp, line 64

Notes = Replace(Notes, /\r|\n/g, "<br />")
-----------------------^

Cheryl dc Kern
 
Ok, ok I see, change to this:

Code:
Notes = Replace(Notes, Chr(10), "<br />")
Notes = Replace(Notes, Chr(13), "<br />")

The way your Replace works doesn't recognize RegExp patterns, so this is equivalent to what I had above.





[monkey][snake] <.
 
That worked beautifully! Thank you! Can you tell me where I can find a list of the chr codes for my reference, by any chance?

Cheryl dc Kern
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top