I want that in first table lines and quantity is calculated on checkbox check/uncheck and quantity is sum of second table inputs value by unit of measurements
but it seems i m doing something wrong
@Dormilich I m still bad at javascript/jquery i guess this is wrong? $('#rtable').find('.sum_values:checked').reduce(function () { also console returns TypeError: $(…).find(…).reduce is not a function
Correct. The available jQuery methods can be found by looking up http://api.jquery.com/<name-of-the-method> (hint: reduce() is not a jQuery method). But I have already given you the method to link jQuery and reduce().
Here’s a more structured (and readable version) using ES6 features:
var total = [...list] // list-to-array conversion
.filter(e => e.checked) // only checked checkboxes
.map(e => e.value) // element to value
.map(v => parseFloat(v)) // string to number
.reduce(((sum, val) => sum + val), 0) // numbers to sum
The same version in jQuery:
var total = $('#rtable')
.find('.sum_values:checked')
.get()
.reduce(function (sum, val) {
return sum + parseFloat(val)
}, 0)