How do i find dynamic average for not the 20 input boxes

Posted by alpho07 on Stack Overflow See other posts from Stack Overflow or by alpho07
Published on 2012-09-03T14:31:07Z Indexed on 2012/09/03 21:38 UTC
Read the original article Hit count: 115

Filed under:
|
|

How do i find dynamic average for not the 20 input boxes with ".num" class but even just five out of 20. I have done it as below but it won't work

$.fn.sumValues = function() {
        var sum = 0; 
        this.each(function() {
            if ( $(this).is(':input') ) {
                var val = $(this).val();
            } else {
                var val = $(this).text();
            }
            sum += parseFloat( ('0' + val).replace(/[^0-9-\.]/g, ''), 10 );
        });
        return sum.toFixed(2);
    };

    $(document).ready(function() {
        $('input.price').bind('keyup', function() {
            $('span.total').html( $('input.price').sumValues()/$('.num').length );
        });
    });

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery