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
Post a Comment