1: How can a get the subtotal value based on each item value
2: When all calculation (each) is done how can I fire a function that will contain the subtotal value.
var subtotal = 0;
//Check each price
$.each(item, function() {
var itemprice = $(this).val();
var subtotal = subtotal + itemprice;
});
//When all items are added in the subtotal do something...
Assuming that
itemis a collection of prices…Remove the
varbefore the secondsubtotalotherwise you are declaring a local variable rather than accessing the global one.If the above code is already part of a function, then there is no need to call another function to do something with the subtotal (unless that code will be reused).