2
var name= '<bean:write name="frmUser" property="name" filter="true" />';

When jsp render code then it appears like this

var name = 'Ishwar Lal \';

JavaScript shows error on it.

"Ishwar Lal \" is the sample value. I don't know what value will come. But issue appears when back slash come in javascript.

Ishwar Lal
  • 646
  • 7
  • 20

2 Answers2

0

in Javascript you escape character with a backslash as well. When you want to write one in a string, use var str = "Ishwar Lal \\"

Ba5t14n
  • 719
  • 2
  • 5
  • 20
  • "Ishwar Lal \". Is the sample value. I don't know what value will come. – Ishwar Lal Jan 30 '15 at 08:13
  • sorry, I dont understand what your problem is exactly, could you explain it a bit more detailed? – Ba5t14n Jan 30 '15 at 08:16
  • I have updated my question. Basically in my db there are number of names. Any name may contains "\". I can not hard code only for "Ishwar Lal \\" value. – Ishwar Lal Jan 30 '15 at 08:44
0

This javascript function will escape all special characters..

function addslashes(str) {
      return (str + '')
        .replace(/[\\"']/g, '\\$&')
        .replace(/\u0000/g, '\\0');
    }

Credits: http://phpjs.org/functions/addslashes/

Dyrandz Famador
  • 4,499
  • 5
  • 25
  • 40
  • I have used your mentioned method but not resolved. This message is coming "Unterminated string Constant" in JS error. @Dyrandz – Ishwar Lal Jan 30 '15 at 09:20