Forum Moderators: open

Message Too Old, No Replies

Using Javascript To Subtract Dynamically Generated Numbers

javascript subtract

         

kankles

9:24 pm on Sep 24, 2010 (gmt 0)

10+ Year Member



Hi,

I'm promoting a buy $500 in product get free shipping offer. I'd like to add a custom message that subtracts a dynamically generated subtotal number from $500.

IE. Add $430 to your cart to get free shipping.

If it helps, the subtotal is wrapped in the following tags:

 <p class="subtotal">
<label>Subtotal:</label> $70.00
</p>

MichaelBluejay

3:50 am on Sep 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Can you put the subtotal into an <input type=hidden> field? Then it will be easy to work with.

<script type=text/javascript>
theSubTotal = document.getElementById('subtotal').value-0;
remainder = 500-theSubTotal;
</script>

<input type=hidden id="subtotal" value="70.00">


Note that I subtract 0 from the value. That's standard practice to make sure when you get a number value that JS treats it like a number and not like a string.