Reputation: 25
Is it possible to assign a BigCommerce global variable to a javascript var in order to modify the text appropriately? For example:
<script type = "text/javascript">//<![CDATA[
var test = %%GLOBAL_ProductDesc%%;
//insert modification to "test" here
$(document).ready(function() {
document.getElementById("text").innerHTML = test;
});
//]]>
</script>
EDIT:
I tried doing:
var test = '%%GLOBAL_ProductDesc%%'
This works fine for some descriptions but not all. What could be the reason for this?
Upvotes: 2
Views: 1677
Reputation: 1493
the reason you may have had issues when attempting to assign the variable is if your product description has single quotes in inside of it.
My recommendation would be to set the variable equal to the container element of the description.
<div id="ProductDescription">
%%GLOBAL_ProductDesc%%
</div>
Then the JS
var productDesc = $('#ProductDescription').html();
or if you just want plain text
var productDesc = $('#ProductDescription').text();
Upvotes: 1