I'm getting this error when I try to call a Javascript function from a Smarty page. I know what the error is about generally - but I don't understand why it happens in this case.
The function which throws the error is called in the following manner:
<a href='#' onClick="showActualSize({$id_product},'{$realsize|escape:'htmlall'}');">Actual Size</a>
In this case, the variables have the following values;
$id_product = 544; $realsize = "Imperial: LR14 Metric: MN1400";
I used escape:'htmlall' to escape any special chars that may appear in $realsize but, as you see, there aren't any in this example.
However, when I look at the page source code, there appear to be new lines in the $realsize variable, as the source looks like this:
<li><a href='#' onClick="showActualSize(544,'Imperial: LR14
Metric: MN1400
');">Actual Size</a></li>
Am I looking at some hidden characters that are causing the error? How can I get around this?
{$realsize|escape:'htmlall'|escape:javascript}fixed the issue. I used html escape because the string could contain quotes etc.