I thought it was more on the lines of $(".total").val(tot) considering he said the input had the class "total".
Michel Belleville 2009/11/13 Dan G. Switzer, II <dswit...@pengoworks.com> > palgo: > > You probably mean: > > $("#total").val(tot); > > The selector $("total") would be looking for an element named total (i.e. > <total />,) where as $("#total") looks for an element with an id of "total". > > -Dan > > On Fri, Nov 13, 2009 at 10:13 AM, palgo <rusha...@gmail.com> wrote: > >> 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? >> >> >> >