I just can’t get this to work for some reason.. Here is the page setup:
I have 3 <span> tags:
[CODE]<span id=”carttotal”></span>
<span id=”shipping”></span>
<span id=”ordertotal”></span>
When A user clicks a radio button for their shipping method:
[CODE]
<input id=’priority’ onclick=”updatetotal(‘priority’)” type=”radio” name=”shipping” value=”priority” />
I have a script that should insert the shipping total in to the <span>, which it does, but what I can not get it to do is to take that value, add it to the value in the ‘carttotal’ <span> and output this to the ‘ordertotal’ <span>.
Here is my script:
[CODE]
<script type=”text/javascript”>
function updatetotal(id)
{
if (id === ‘priority’){
document.getElementById(‘shipping’).innerHTML=”5.00″; //set to $5.00 shipping
var cart_total = document.getElementById(‘carttotal’).value; // this never gets set. always comes up undefined…
var shipping = document.getElementById(‘shipping’).value;
var order_total = parseFloat(cart_total) + parseFloat(shipping);
document.getElementById(‘ordertotal’).innerHTML = order_total;
}
else if (id === ‘parcel’){
//nothing really completed here yet, testing using the priority radio button
document.getElementById(‘shipping’).innerHTML=”3.00″;
document.getElementById(‘ordertotal’).innerHTML=”5.00″;
}
}
</script>
The text in the ‘ordertotal’ <span> gets set to $NaN, and I have tried many other combinations and tricks, but I always get $NaN or undefined..