Solved

Coldfusion, Jquery and special characters

Posted on 2012-04-09
7
386 Views
Last Modified: 2012-04-14
I am using jquery to populate a form.   Here is the way that I am doing it:

<script type="text/javascript">
      $(document).ready(function(){
            <cfoutput query="qry_sel_info">
                  $("##notes").val("#notes#");
            </cfoutput>
       });
</script>

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")#>
$("##notes").val("#anotes#");

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
0
Comment
Question by:trifecta2k
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 37823640
(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.
0
 
LVL 5

Accepted Solution

by:
trifecta2k earned 0 total points
ID: 37823715
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!
0
 
LVL 52

Expert Comment

by:_agx_
ID: 37823727
Ok, kewl. I couldn't remember off the top of my head :)
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 5

Author Comment

by:trifecta2k
ID: 37824030
agx..you wrote no points...how do I accept this as a solution without giving you points?
0
 
LVL 52

Expert Comment

by:_agx_
ID: 37824128
I think you can accept one of your own comments as an answer.
0
 
LVL 5

Author Comment

by:trifecta2k
ID: 37824187
OK.  I will do that.  Thanks again for all of your help.
0
 
LVL 5

Author Closing Comment

by:trifecta2k
ID: 37845934
agx didn't want points so I selected my own answer as the solution.
0

Featured Post

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question