Thanks to some help I received yesterday I’ve got some dynamic summing working on an HTML table based on user input and selections from a select menu. I’ve run into one problem though that’s stumped me. If you look at my jsfiddle:
http://jsfiddle.net/fmdataweb/T5xtL/13/
if you enter data as follows:
Row 1: Fruit= Apple Qty = 100
Rwo 2: Fruit= Banana Qty = 200
Everything works as expected for the totals:
Total Apples 100
Total Bananas 200
If you now change Row 1 Fruit selection from Apple to Banance the sub totals are now:
Total Apples 100
Total Bananas 300
The Bananas total has updated correctly but the Apples total hasn’t changed – it should now be zero/0.
Any ideas what this is happening?
Update: Here’s a jsFiddle of what I meant since it was unclear before
At the beginning of the calc function you should reset everything back to zero. The issue is that you only reset to zero if one of the fruits is selected in a drop down. In your case apple wasn’t selected so it was never reset! Hope this helps.