No JS experience at all. I make a super simple calculator. 2 checkboxes where the cost is registered. One checkbox has an input with the number by which the result of this checkbox is multiplied. And the total should get to the total.
If separately, I mark checkboxes, then everything works. If together then NaN.
var rozetka = 0; var rozetkaCell = 0; var check = 0; $('.input__check').on('change', function () { check = 0; $('input:checkbox:checked').each(function () { if ($(this).prop("checked")) { check = Number(check) + Number($(this).data('check')); } }); summ(); }); $('.rozetka').on('change', function () { rozetka = 0; $('input:checkbox:checked').each(function () { if ($(this).prop("checked")) { rozetka = Number(rozetka) + Number($(this).data('rozetka')); } }); summ(); }); $(".rozetka-cell").change(function () { rozetkaCell = $('.rozetka-cell').val(); summ(); }); function summ() { rozetka = Number(rozetka); rozetkaCell = Number(rozetkaCell); check = Number(check); main = rozetka * rozetkaCell; $("#itogo").text(check + main + ' руб.'); }; <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script> <form action=""> <input class="rozetka" type="checkbox" name="rozetka" id="" data-rozetka="50" value="1"><span>Установка розеток</span> <input class="rozetka-cell" type="number" min="0" name="rozetka-cell" id="" value=""><br> <input class="input__check" type="checkbox" name="lystra" id="" data-check="200"><span>Установка люстры</span> </form> <p>Итого: <strong><span id="itogo"></span></strong></p><br>