My Description contains an apstrophe('). How to escape it.
<a href='javascript:select("<%= pageBean.replace(list.getColumn(0), "'", "'") %>",
"<%= pageBean.replace(list.getColumn(1), "'", "'") %>");' title="<%=selRpt%>">
<span class='img-view'></span></a>
"<%= pageBean.replace(list.getColumn(1), "'", "'") %>"
is the description part in my JSP Scriptlet which contains apstrophe(')
My HTML View
<a href='javascript:select("JWCCA5",
"Worker's Compensation Form - California Form 5020(New)");'
title="Select Report"><span class='img-view'></span></a>
This JavaScript error unterminated string literal occurs if there is string which is not terminated properly. String literals must be enclosed by single (') or double (“) quotes.
A "string literal" is a sequence of characters from the source character set enclosed in double quotation marks (" "). String literals are used to represent a sequence of characters which, taken together, form a null-terminated string.
For reserved HTML characters you should use HTML entities. An apostrophe is then reprecented as '
:
<a href='javascript:select(
"<%= pageBean.replace(list.getColumn(0), "'", "'") %>",
"<%= pageBean.replace(list.getColumn(1), "'", "'") %>");' title="<%=selRpt%>">
<span class='img-view'></span></a>
Use \'
Inside a HTML tag, you need to turn the string into HTML entities, so the quote becomes '
Inside pure JavaScript, you could also escape the quote with a \'
Usually \' should work, but it seems that sometimes you need to use '' (double apostrophe).
Try this one:
<%= pageBean.replace(list.getColumn(0), "'", "\'" %>
or:
<%= pageBean.replace(list.getColumn(0), "'", "''"
One of them should work (from my experience).
For attributes within HTML tags, I would use " (quotation mark) rather than ' (apostrophe).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With