Escape an apostrophe under javascript
In Javascript, an apostrophe (single quote) into a string itself enclosed by apostrophes cause an error.
To troubleshoot, you should escape the apostrophe by heading the backslash character to get to the Javascript interpreter that it is an apostrophe within the string.
However, when the string is inserted dynamically, you should escape any characters that can cause an error (apostrophe, quote or double quote, backslash).
addslashes
() under PHP is a useful feature for automating the escape special characters. The function below is an excellent alternative for JavaScript:
function addslashes (ch) (
ch.replace ch = (/ \ \ / g, "\ \ \ \")
ch.replace ch = (/ \ '/ g, "\ '")
ch.replace ch = (/ \ "/ g," \ \ \ "")
return c.
)