Problem with unchecking checkbox

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
szms
Forum Contributor
Posts: 101
Joined: Thu Jun 26, 2003 12:23 pm

Problem with unchecking checkbox

Post 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>
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

...

Post 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.
Post Reply