profitcalc.js 843 B

1234567891011121314151617181920212223242526
  1. const checkboxes = document.querySelectorAll('input[name="profitcalc"]');
  2. const profitCalcContainer = document.getElementById('profitcalccontainer');
  3. function updateProfitSum() {
  4. let totalSum = 0;
  5. checkboxes.forEach((checkbox) => {
  6. if (checkbox.checked) {
  7. totalSum += parseFloat(checkbox.getAttribute('pfstc')) || 0;
  8. }
  9. });
  10. if (totalSum > 0) {
  11. profitCalcContainer.textContent = totalSum.toFixed(2);
  12. profitCalcContainer.classList.add('wehaveprofit');
  13. profitCalcContainer.style.display = 'block';
  14. } else {
  15. profitCalcContainer.textContent = '';
  16. profitCalcContainer.classList.remove('wehaveprofit');
  17. profitCalcContainer.style.display = 'none';
  18. }
  19. }
  20. checkboxes.forEach((checkbox) => {
  21. checkbox.addEventListener('change', updateProfitSum);
  22. });