Thank you! Works perfect!
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;
}
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
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
4 matches
Mail list logo