I have:
function showMessage(message) {
alert(message);
}
But when the message comes dynamically from the server as(example): "Men's" it doesn't work.
I've tried:
function myEncode(message) {
return message.replace("'", "\'");
}
showMessage(myEncode(message));
Doesn't seem to work. This is a simple example, the actual code is more complicated, but essentially this is the issue.
showMessage(myEncode('Men's'))? So your JavaScript is already broken at that point - so trying to replace something in JavaScript if you already have a JS syntax error is of course pointless (D'oh!). Do the escaping in your server-side code before you output that value as a JS string value.