1
I have a tab, where the user should put the amount and value of each item. He can add as many items as he wants. At the bottom of the page, it will show the total result of the sum of all possible lines that the user adds.
See Fiddle next to understand better.
Jsfiddle: https://jsfiddle.net/f0aggozk/1/
This structure is practically finished. The only problem that is happening is that when adding a new field, if any of the values are empty, the total value displayed is empty. I believe that it is necessary to make the calculation for each one of the lines, and add up the value of all the lines.
need to be with pure jquery? There are some frameworks that make this quite easy.
– Guto
I am open to alternatives, but I believe that my code is only a few details to run it without bugs.
– Mauro Alves
The problem is that when you add a new line you are zeroing out? If so, your validation to set the total to zero on line 46 this zeroing out the total. If the total of the last line is zero, you are zeroing out the total. I made a small adjustment see here if it is ok: https://jsfiddle.net/5z0qavps/1/.
– cbonomini
Actually, adding a new line was not the problem. The calculation occurred when changing the input. By keeping it empty or deleting it, the bug of zeroing everything happened. But the validation you added really solved it. Add as answer to the question, please. :)
– Mauro Alves
@Mauroalves how good it worked, I added in response.
– cbonomini
Thank you @cbonomini
– Mauro Alves