Link to home
Start Free TrialLog in
Avatar of tribalboy3000
tribalboy3000

asked on

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

Avatar of ChetOS82
ChetOS82
Flag of United States of America image

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?
Are you checking what is being submitted with the form in your server side?
Avatar of tribalboy3000
tribalboy3000

ASKER

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.
In that case you probably need to convert data coming out of the database into safe data before using it on the web page.
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
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.
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.
ASKER CERTIFIED SOLUTION
Avatar of tribalboy3000
tribalboy3000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial