Trying to calculate the average of 2 fields using javascript.
I want it to be able to output the value on another field.
$('.inv input').on('change', function(){
var sum = 0, n = 0;
$('.inv input').each(function(){
if ($(this).val() != ''){
sum += parseFloat($(this).val());
n += 1;
}
});
$('.invave input').val(sum/n);
});
The class of the two values being 'inv' and the output class on the field with average is 'invave'
Subsequently I wanted to see what I need to setup for summing multiple fields, some sums need to be negative.
IDs: q4, -q5, q6,-q7,q8