Page 1 of 1

Problem with unchecking checkbox

Posted: Tue Jul 29, 2003 7:39 pm
by szms
Please take a look of this code. I am having problem when I try to uncheck any item. I keeps the cost for unchecked item. Can you please help me to solve this. Thank you.

<html>

<head>
<title></title>
<script type="text/javascript">
<!--
var total = new Number();
function showTotal()
{
var tax = total * (5/100);
var finalTotal = total + tax;
alert("Your total cost is: $" + finalTotal.toFixed(2) + "");
return false;
}
//-->
</script>
</head>

<body>



<form action="">
<p>
<input type="checkbox" onclick="total += 0.59"/> Apple (59 cents each) <br/>
<input type="checkbox" onclick="total += 0.49"/> Orange (49 cents each)<br/>
<input type="checkbox" onclick="total += 0.39"/> Banana (39 cents each)<br/><br/>
<input type="submit" name="submit" value="Submit" onclick="showTotal()"/>
</p>
</form>



</body>

</html>

...

Posted: Wed Jul 30, 2003 12:57 am
by kettle_drum
It would be a lot easier if you just did all the adding up when the user presses submit in the showTotal() function.