2

I have got something like the following in my jsp:

var test = <%=Num%>;

and Num in this case is something like 12345678,john,smith.

But when I load the page I get the following error:

Error: SyntaxError: unterminated string literal

Can anyone help me out, thanks

ComeRun
  • 921
  • 1
  • 20
  • 38

4 Answers4

2

As you have not only number in your value, it's not a number so you need to treat it as a String and wrap your value in quotes

var test = "<%=Num%>";
999k
  • 6,257
  • 2
  • 29
  • 32
aymankoo
  • 653
  • 6
  • 12
  • Still get the error message Error: SyntaxError: unterminated string literal Line: 2816, Column: 15 Source code: var test = "12345678,john,smith – ComeRun Apr 11 '13 at 05:15
  • It's telling you you must have matching quotes. Perhaps the last character in the string is a backslash (\) that is quoting the quote (")? – RobG Apr 11 '13 at 06:14
  • it could be \n as of line break! could you offer a solution if that the case? – ComeRun Apr 11 '13 at 06:27
1
var test = '<%=Num%>';

Wrap it in quotes

TGH
  • 38,769
  • 12
  • 102
  • 135
0

Try var test = "<%=Num%>";

Ken Herbert
  • 5,205
  • 5
  • 28
  • 37
  • Still get the error message Error: SyntaxError: unterminated string literal Line: 2816, Column: 15 Source code: var test = "12345678,john,smith – ComeRun Apr 11 '13 at 05:16
0

Please avoid using scriplets

 var test = "${Num}";
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307