Solved

Coldfusion, Jquery and special characters

Posted on 2012-04-09
7
383 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can't get javascript video player button to work 10 23
Asp response.write to clients 6 34
Prevent certain words from being typed in a form 6 29
Slush on text 2 11
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

749 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