I have a product website that lists the product price based on a box of 20 units ($20/box for this example). I’d like to show the per-unit cost next to the box cost, or $1.00.
The HTML already defines [PRICE] as the tag for the price of the box. I thought it would be simple enough to divide this by 20 using a <script>
, but I’m wrong!
I came up with this:
<!--START: quantity_items-->
<tr>
<td>[lowbound][highbound]</td> //this the volume band; example - buy 3 to 5 boxes and pay a certain price, called [PRICE].
<td>[PRICE]
<script>
var numOne=[PRICE], numTwo=20, res;
res = numOne/numTwo;
document.write(" ($" + res + "/unit)");
</script>
</td>
</tr>
<!--END: quantity_items-->
…with the expected outcome being:
3 – 5 || $20.00 ($1/unit)
This is a table, obviously (td and tr tags), so the calculation would repeat for each row.
Now, calculations work using this tutorial (I can see them on my site):
<script>
var numOne=12, numTwo=20, res;
res = numOne + numTwo;
document.write(" ($" + res + "/unit)");
</script>
But when I replace the 12 with [PRICE], it fails. What is happening here? I assume that [PRICE] needs to be introduced into the <script>
somehow, but how it that done?