Hello there, I’m working on a web site, where customer select one size of pizza from radio buttons. The size has different prices depending of what radio button customer select. at the bottom, customer will see a text box where price will be display. then if customer is student will receive a 10% off of discount, checking a box and price will be decrease.| My problem is the follow: I don’t know how to calculate % off, updating the price.
Javascript:
[code=html]function updateTotal()
{
var sizeAll = document.getElementsByName(‘product’);
var i = sizeAll.length;
var size = 0;
var topAll = document.getElementsByName(‘discount’);
var c = topAll.length;
var top = 0;
var total = document.getElementById(‘total’);
while(i–)
{
if(sizeAll[i].checked)
{
size = parseFloat(sizeAll[i].value);
}
}
if(size > 0)
{
while(c–)
{
if(topAll[c].checked)
{
top += parseFloat(topAll[c].value);
}
}
total.value = ((size / 100) * top).toFixed(2);
}
else
{
total.value = size;
}
return true;
}
Html Form:
[code=html]Pizza Size: (Small 5 Euro- Medium 8 Euro- Large 12 Euro)
<td id=”radios” >
<input type=”radio” name=”product” value=”5.00″ onclick=”updateTotal()”>Small(10″)
<input type=”radio” name=”product” value=”8.00″ onclick=”updateTotal()”>Medium(12″)
<input type=”radio” name=”product” value=”12.00″ onclick=”updateTotal()”>Large(14″)
Student receive a 10% discount.
<td id=”checkboxes” >
<input type=”checkbox” name=”discount” onclick=”updateTotal()” value=”0.10″>
Total Cost:
<input type=”text” name=”total” id=”total” size=”10″ readonly=”readonly”>