Get average from inputs on change
<p>I want to get the average by input value, and I have 5 input fields.
This is what I found but it is not with inputs using an onchange event, can someone help me with that?</p>

<pre><code>var total = 0,
    valid_labels = 0,
    average;

$('.td_input').each(function () {
    var val = parseInt(this.innerHTML, 10);
    if (val !== 0) {
        valid_labels += 1;
        total += val;
    }
});

average = total / valid_labels;
$('.average').val(average);
</code></pre>

<p>jsfiddle
<a href="http://jsfiddle.net/Pqd8B/1/" rel="nofollow">http://jsfiddle.net/Pqd8B/1/</a></p>
