How to assign a string to a variable in javascript when the string has a single quote in it -


in program there variable name 'quotes' takes input string api call.
program doesn't work when string has single quote in it.

<script>     var quotes = "empty"         if(user.quotes)            quotes = user.quotes;    // string 'quotes' variable </script> 

can 1 please tell me how fix problem?

replace single quote (escape php):

<script>     var quotes = "empty"         if(user.quotes)            quotes = user.quotes.replace(/'/g,"\\\'");    // string 'quotes' variable </script> 

then wherever use quotes, replace "\'" "'".


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -