I have the following php code
$bigImageSrc = 'images/'.$prodXML->bottles->bottle[$i]->bigImage;
$text = $prodXML->bottles->bottle[$i]->title;
$title = $prodXML->bottles->bottle[$i]->text;
echo "<a href=javascript:void(0); onClick=showProduct('$bigImageSrc', '$text', '$title');>
but I’m getting this error:
syntax error
showProduct(‘images/image1.jpg’,
It works for just one var in the showProduct function.
Any ideas where I’m going wrong?
You have no quotes around your onClick attribute, which means that the space after
'$bigImageSrc',is interpreted as the end of that attribute value.You should enclose every attribute in HTML within quotes, to prevent a lot of problems.
Eg.
You should also not be using javascript:void(0); as an href attribute, as it breaks when Javascript is disabled or someone tries to “open in new window”, “bookmark”, “open in new tab” etc on that link. But that’s a separate issue.