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>
Problem with unchecking checkbox
Moderator: General Moderators
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
...
It would be a lot easier if you just did all the adding up when the user presses submit in the showTotal() function.