set a text from a java object with new lines to a javascript variable in JSP
Posted
by machaa
on Stack Overflow
See other posts from Stack Overflow
or by machaa
Published on 2010-03-21T15:24:20Z
Indexed on
2010/03/21
15:31 UTC
Read the original article
Hit count: 394
jsp
|JavaScript
Hi,
I've a Java String with new lines(\n), say for example
String value = "This is a variable\n\nfrom\nJava";
Now I've to set this to a Javascript variable in a JSP file,
<script>var val = '<%= value %>';</script>
But because of the new lines in the above line, I'm getting javascript error "Unterminated String".
Please help me.
© Stack Overflow or respective owner