Rezylience
Rezylience

Reputation: 25

BigCommerce -- Assign global variable as javascript variable

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

Answers (1)

tekstrand
tekstrand

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

Related Questions