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

Coldfusion, Jquery and special characters

I am using jquery to populate a form.   Here is the way that I am doing it:

<script type="text/javascript">
            <cfoutput query="qry_sel_info">

The problem I'm running into is special characters.  Users are entering single quotes (which in this case works), double quotes, and hitting <enter> after lines.  How can I fix this so it will show all the special characters without having problems.  

I'm not too good at regular expressions, but I gave it a shot and here is what I've tried so far:

<cfset aNote = #REReplace(admin_note,"([\'\""])","\\\1", "all")#>

This works to a point.  The problem is that in my textarea it shows:
&quot;This is a 'test'&quot;

The single quotes work the way I want, but I don't want &quot;, i actually want the " to show.  Plus I have no idea what to do with a <enter>

Another issue is that I have a TON of fields that this effects.  What is the easiest way to do this without having to use cfset on every field?  I would assume a function...but i'm fairly new to jquery.  

Thanks in advance for your help
  • 4
  • 3
1 Solution
(no points ..)

I haven't tested it, but I normally use jsStringFormat which properly escapes input for use in javascript.

Plus I have no idea what to do with a <enter>
Depends on the field type.  Most html elements (except maybe textarea) can't display ascii new lines ie chr(10). If you want to preserve/display them, convert them to html line breaks instead ie <br>.  

So maybe something like    

            $("##notes").val( '#jsStringFormat( replace(notes, chr(10), "<br>", "all") )#' );

Another issue is that I have a TON of fields that this effects.

Then you might consider creating a wrapper function, and call it instead.
trifecta2kAuthor Commented:
Looks like jsStringFormat works by itself.  I don't need the chr(10) stuff.  jsStringFormat already escapes newline.  I guess that's all I was looking for.  Thanks!
Ok, kewl. I couldn't remember off the top of my head :)
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

trifecta2kAuthor Commented:
agx..you wrote no points...how do I accept this as a solution without giving you points?
I think you can accept one of your own comments as an answer.
trifecta2kAuthor Commented:
OK.  I will do that.  Thanks again for all of your help.
trifecta2kAuthor Commented:
agx didn't want points so I selected my own answer as the solution.
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

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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