|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Problem with unchecking checkbox
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> |
|
#2
|
||||
|
||||
|
RE: Problem with unchecking checkbox
you need to change the onclicks to onchange used to call a function and in the function calculate the total on the fly.
|
|
#3
|
|||
|
|||
|
RE: Problem with unchecking checkbox
Thank you for your help. Little bit code may help more.
|
|
#4
|
||||
|
||||
|
RE: Problem with unchecking checkbox
the forum is not to have people write your code for you it's for you to get help when you can't figure out how to do something. If someone totally writes every function you ever need you aren't going to learn very much and will be still asking for the same help in a year. Do a search on google for - onChange javascript and you'll get a host of tutorials on how to implement this property basically it's onchange(yourfunction();) and in your function you need to check which boxes are checked and calculate the total right then.
|
|
#5
|
|||
|
|||
|
RE: Problem with unchecking checkbox
Hey.. I am kind of new in Java script so it would be great if someone help me with the code. Thank you.
|
|
#6
|
||||
|
||||
|
RE: Problem with unchecking checkbox
I wasn't trying to be mean but I have been a memeber of baords like these for about 7-8 yrs (although they sure look better than they used to) and eventually what happens to people who just keep asking for someone else to do the whole thing for them is that everyone stops helping them. Bottom line, I told you what was wrong, you're simply adding to your total every time the check box is clicked and there is no code to remove that addition so it doesn't work correctly.
you need to take some time and read a little about how to build a function and callit with and event handler. |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > Problem with unchecking checkbox |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|