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

Escaping plus symbol (+) in textarea

I have a form with a textarea that is outputting data from my database, when a (+) symbol is entered in the form and submitted like "C++" it gets saved in the database correctly but displays "C  " without the (+) symbols. I believe it is getting taken out of the page via javascript and have tried the code below but it doesn't work.
<script>
escape( 
	objParams[ strKey ] 
	 
	// Escape the "+" manually.
	).replace( 
		new RegExp( "\\+", "g" ), 
		"%2B" 
		) 
</script>

Open in new window

0
tribalboy3000
Asked:
tribalboy3000
  • 3
  • 2
  • 2
  • +1
1 Solution
 
ChetOS82Commented:
Is there any javascript running on the page that might do this?  You say it gets saved as "C++", so is the issue when you try to display the form again?
0
 
SRigneyCommented:
Are you checking what is being submitted with the form in your server side?
0
 
tribalboy3000Author Commented:
The form is actually a CFFORM on a Coldfusion page. I know that when CF is interpreted javascript is sometimes added to the source code. When the form is submitted ( C++) it is being stored in the database as (C++), when it is being passed back to the web page it is not displaying the (++) just (C  ) is showing.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
SRigneyCommented:
In that case you probably need to convert data coming out of the database into safe data before using it on the web page.
0
 
scrathcyboyCommented:
an HTML text area is designed only for basic text (letters and numbers) and no special characters.  Whether going into CF, or a form submit, the text area does not preserve special characters, carriage returns, line feeds, and any special formatting, including HTML.  If you want to preserver these, you use the RICH text area, which is a simple plug in to any web page -- try it, you will likely find it works fine --

www.textarearich.com/
www.dynamicdrive.com/dynamicindex16/richtexteditor/index.htm
www.tcpiq.com/tcpIQ/HTMLRichTextArea/
www.topshareware.com/HTML-Rich-Text-Area-download-1456.htm
0
 
tribalboy3000Author Commented:
Im using Rich Text in my CFForm, the problem I found is that the textarea is being passed thru the url and the (+) symbol is being replaced by a blank space.
0
 
ChetOS82Commented:
How is the textarea being populated?  You say "thru the url", but that doesn't make sense to me.

A plus symbol is not a special character to a textarea, but it is to a URL (the plus symbol is a space), I just don't understand your process of getting the value out of the database and into the textarea.
0
 
tribalboy3000Author Commented:
I figured it out! the form "value" was being passed thur a url and the (+) symbol when being used in the textform was not going thru. Example (C+ or C++). I had to use a replace to change out the (+) to (%2B) which is the html format for (+).
<a href="frm_InsertCurMod.cfm?COURSETITLE=#Trim(COURSETITLE)#&FORMVALUE=
#Replace(Replace(COURSE_DESCR,"++","%2B%2B"), "+", "%2B")#&ACAD_PLAN=#ACAD_PLAN#"> Edit Course Description</a>

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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