Skip to content
Advertisement

How do I sum all checkboxes in javascript / jquery and how can it be dynamically displayed in a bootstrap label?

I am trying to get it dynamic but I just can’t get it done.

The label must add up all checkboxes and if a checkbox is checked or unchecked the total count number must be up or down.

If one checkbox is clicked and it is checked, the label must go up with +1, if the checkbox is clicked and the checkbox is unchecked then the label must go off with -1.

JavaScript

JavaScript

Advertisement

Answer

You need to add an event listener on each of the checkboxes:

JavaScript
JavaScript

Check out a working example: https://codesandbox.io/s/intelligent-nash-mbohj?file=/src/index.js

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