temp is undefined, so you're adding undefined to the first value in your loop. Set temp = 0;
Also, unless you're planning on using it elsewhere, you don't need to assign var obj. And, is there any reason you're using document.getElementById("grand_total").innerHTML instead of $ ('grand_total').html()? On Mar 6, 4:58 pm, shallowman <nha...@gmail.com> wrote: > Hello all, > > I am trying to add the values from a variable number of select drop > downs. I have assigned each select element that I want to add a class > of "weight" to make searching for them easier. The goal is to have all > of the numeric values from each select element with the class "weight" > added together and displayed in an html element with the id > "grand_total" > > My code so far: > > <script type="text/javascript" src="scripts/jquery-1.3.2.min.js"></ > script> > <script type="text/javascript"> > > function weightTotal() > { > > var all = $(".weight"); > var temp; > var obj = jQuery.each(all, function() { > if(this.value != "") > { > temp = temp + > parseInt(this.value); > } > }); > > > document.getElementById("grand_total").innerHTML = temp + "%"; > > } > > </script> > > So far, the only thing displayed in the "grand_total" element is NaN% > > Can anyone help a jQuery newbie out? Thanks in advance.