+1  A: 

Try this:

var values = $("input[name^='min']").map(function(){
    return isNaN(this.value) ? [] : +this.value;
}).get();

var min = Math.min.apply(null, values);

And then you can add that min-value to another input field like so:

$('#some-input').val(min);
J-P
+1  A: 

You might want to have a look at the jQuery Calculation Plug-in. The syntax for your example would be something like this:

var MinVal=$("input[name^='min_field_']").min(); // Get minimum value
var MaxVal=$("input[name^='min_field_']").max(); // Get maximum value
var AvgVal=$("input[name^='min_field_']").avg(); // Get average value

This would be faster version:

var MinField=$("input[name^='min_field_']");

var MinVal=MinField.min(); // Get minimum value
var MaxVal=MinField.max(); // Get maximum value
var AvgVal=MinField.avg(); // Get average value
Gert G
Right, that was exactly the site which led me to my first try of snippet.Btw. you helped me with another question I put back in my mind. Thanks for that
Faili
A: 

Without plugins you can do something like this JSFiddle

Array.prototype.avg = function() {
    var total = this[0];
    var len = this.length;
    for (var i = 1; i != len; i++) total += this[i];
    return total / len;
}

Array.prototype.min = function() {
    return Math.min.apply( Math, this );
}

Array.prototype.max = function() {
    return Math.max.apply( Math, this );
}

var values = $("input[id^='field_']").map(function(){
    var value = $(this).val();
    if (value.length == 0 || isNaN(value)) {
        return 0;
    } else {
        return parseFloat(value);
    }
}).get();

$('#max').val(values.max());
$('#min').val(values.min());
$('#avg').val(values.avg());

​ The prototypes should help in future.

Metalshark
`max()` and `min()` can be improved, see: http://ejohn.org/blog/fast-javascript-maxmin/
Tomalak
Thanks - these are handy to know. Always thought it was a bit off for it to not accept an array.
Metalshark
+2  A: 

Using other libraries are one way to do it, but solving small issues by hand would nice. Change the selectors in code below, and check.

$(function(){
    sel = $('.field')
    min_field = $('#min');
    max_field = $('#max');
    avg_field = $('#avg');
    len = $(sel).length;
    $(sel).change(function(){
       sum = 0
       list = []
       $(sel).each(function(){
            val = Number($(this).val());
            list.push(val);
            sum += val;
        })
        $(min_field).val(Math.min.apply(Math, list))
        $(max_field).val(Math.max.apply(Math, list))
        $(avg_field).val(sum/len);
     })
})

Happy Coding.

simplyharsh
Ty...I understand it, but unfortunately it didn't fulfill my needs. I updated my post how I solved it finally.
Faili