Hello guys, i'm trying to calculate the value of checkbox that chosen (onclick or onsubmit calculate the value).What i'm doing wrong?
<script type="text/javascript">
//<![CDATA[
function calculate_total(id) {
// get a reference to the form using getElementById
var theForm = document.getElementById( id ),
total = 0;
// DON'T use getElementById again, use the form element names, like this:-
if (theForm.DigRacing.checked) {
total += parseFloat(theForm.DigRacing.value);
}
if (theForm.AtariJoystick.checked) {
total += parseFloat(theForm.AtariJoystick.value);
}
if (theForm.FXLightsaber.checked){
total += parseFloat(theForm.FXLightsaber.value);
}
}
</script>
</head>
<body>
<form name ="orderForm" action="#" id="orderForm" >
<div class="advert">
<br />£99.95 <strong>Add to Cart</strong>
<input type="checkbox" name="DigRacing" value="99.95" />
</div>
<div class="advert">
<br />£19.99 <strong>Add to Cart</strong>
<input type="checkbox" name="AtariJoystick" value="19.99" />
</div>
<div class="advert">
<br />£299.95 <strong>Add to Cart</strong>
<input type="checkbox" name="FXLightsaber" value="299.95" />
</div>
<br />
<p><input type="button" name="CheckValue" value = "Calculate cost" onclick="calculate_total(orderForm, total)" />
</form>
</body>
</html>