Solved

Having trouble escaping variables in javascript

Posted on 2010-11-16
1
209 Views
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'>
product.Catalog.init({
    filters: {
        category: ['#url.typ#'],
        department: ['#url.dept#']
    },
    maxFacetOptions: 10
});
</script>

Open in new window

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

Accepted Solution

by:
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'>
product.Catalog.init({
    filters: {
        category: ["#url.typ#"],
        department: ["#url.dept#"]
    },
    maxFacetOptions: 10
});
</script>

Open in new window

0

Featured Post

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

695 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