[jQuery] Re: Building a weight calculator, completely stumped

2009-02-02 Thread Zaliek
Thank you! Works perfect!

[jQuery] Re: Building a weight calculator, completely stumped

2009-02-02 Thread Eric Garside
You could significantly speed things up by throwing a class on all your input classes. $('#calculateweight').click(function(){ var sum = 0; $('input.weighting').each(function(){ sum += $(this).val()*1; }); $('#totalweight').text( Math.ceil(sum) ); return false; }

[jQuery] Re: Building a weight calculator, completely stumped

2009-02-02 Thread Stephan Veigl
Simply use an each loop: $("#calculateweight").click(function() { var sum = 0; $("input[name*='weight']").each(function() { sum += Number($(this).val()); }); $("#totalweight").text( Math.ceil(sum) ); return false; }); @James: looks quite simi

[jQuery] Re: Building a weight calculator, completely stumped

2009-02-02 Thread James
Something like (untested): var total = 0; $("#calculateweight").click(function() { $("input[name^='weight']").each(function() { total += $(this).val(); }); alert('total'); return false; // so the link doesn't go through }); This won't work well if you have other input elem