validate: creating a custom rule that spans several fields

validate: creating a custom rule that spans several fields

(this could be a possibly duplicate post)

I have a bunch of fields like so created on the fly
  1. <input type="text" name="coeff_a">
  2. <input type="text" name="coeff_b">
  3. <input type="text" name="coeff_c"> .. and so on ..
I have set up a rule like so

  1. jQuery.validator.addMethod(
        "perc",
        function(value, element) {
            // all the fields that start with 'coeff'
            var coeff = $("input[name^='coeff']");
            var total;
           
            for (var i = 0; i < coeff.length; i++) {
                total += coeff[i].value;
            }
           
            if (total <= 100) {
                return true;
            }
           
            return false;
        },
        jQuery.format("Please ensure percentages don't add up to more than 100")
    );

















Needless to say, the above is not working. Any ideas what I am doing wrong?