While is a bad habit you may love to leave when you try the iterator approach :
var tot = 0; $('.part').each(function() { tot += $(this).val(); }); $('.total').val(tot); And don't forget classes are accessed with a '.' (total lacked it's '.' in your example). Michel Belleville 2009/11/13 palgo <rusha...@gmail.com> > Hi guys, > > I have several input fields where the value get set (gave them class > name ="part"). > I want to sum up the input values into a last input field with class = > "total", whenever something is being typed in some other fields. > > The input fields with class "part" is not a fixed amount, they can > vary between 2 to infinite. > > So I tried this, which doesn't work: > > $(".whatever").live("keyup", function(event){ > > var arr = $(".part"); > var len = arr.length; > var tot = 0; > > while (i<len) > { > > tot = tot +arr[i].val(); > i--; > } > > $("total").val(tot); > > }); > > Anyone know what I'm doing wrong? > > >