Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">var calculateTotalPrice = function() {
- var checkboxes = document.querySelectorAll('input[type=checkbox]');
- var totalPrice = 0;
- for(var i = 0; i < checkboxes.length; i += 1) {
- if (checkboxes[i].checked) {
- totalPrice = totalPrice + parseInt(checkboxes[i].value, 10);
- }
- }
- console.log(totalPrice);
- document.querySelector('.total-price').innerHTML = totalPrice;
- };
- window.onload = function() {
- var checkboxes = document.querySelectorAll('input[type=checkbox]');
- for(var i = 0; i < checkboxes.length; i += 1) {
- checkboxes[i].addEventListener('click', calculateTotalPrice, false);
- }
- };
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement