Having trouble escaping variables in javascript

Posted on 2010-11-16
Last Modified: 2012-05-10
I have the below javascript snippet: #url.typ# and #url.dept# are coldfusion variable on my site.  Some of the variables have an apostrophe in them, ex. men's   Can I escape them inside this snippet somehow?
<script type='text/javascript'>
    filters: {
        category: ['#url.typ#'],
        department: ['#url.dept#']
    maxFacetOptions: 10

Open in new window

Question by:rkoechel
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
1 Comment
LVL 16

Accepted Solution

jmatix earned 500 total points
ID: 34151378
If you need to escape only apostrophies (not worried about double quotes (") in those values),  then you can use double quotes to surround the JS values as:

<script type='text/javascript'>
    filters: {
        category: ["#url.typ#"],
        department: ["#url.dept#"]
    maxFacetOptions: 10

Open in new window


Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
I'm a Human captcha checkbox 13 43
HTML5 storage and web apps 11 49
Any Way to rotate banner ads from Commission Junction? 2 37
Use Mid in Html 6 22
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

733 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