We have a form that is calculating averages of scores entered in each row of a table. The table has a minimum of 2 rows, but can have upwards of 10 rows. We have the following function to calculate the scores together and get the average using a fixed number.
//Start Add row amount fields together for achievement
$('.cf-table-block').on('blur change', '.achievementSum select', achievementsumtotal);
function achievementsumtotal() {
var s = 0;
$('.achievementSum select').each(function () {
s += parseNumber($(this).val());
});
s = s/2;
$('.achievementSubtotal input').val((s).toFixed(2));
}
function parseNumber(n) {
var f = parseFloat(n); //Convert to float number.
return isNaN(f) ? 0 : f; //treat invalid input as 0;
}
//End Add row amount fields together for achievement
Our problem since the table could have more than 2 rows, how can I count the amount of rows in the table and use that to divide against to get the correct average dynamically?