Skip to content
Advertisement

Add total value according to chapter

I return a dynamic form where the products are separated by chapters. In the example I put there are 3 different chapters. At the end of each chapter, I intend to create an input with the total value of each chapter.

I’m doing it this way:

JavaScript
JavaScript

The problem is that the total value of each chapter is being returned incorrectly. In chapter 1 the total value must be 375.00, in chapter 2 of 891.00 and in chapter 3 of 1170.00.

I’m not able to create the correct condition to return the values ​​as I want, can someone help to solve the problem?

The idea is to create, at the end of each chapter, the total value of the products in that same chapter.

Advertisement

Answer

I just moved the soma += teste to the end, and added a check to reset it after every ‘chapter’.

The code below should work.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement