Hi all,
I wonder if anyone could help me.
I have a web page where there are some text boxes (dynamic amount, could be 3, could be 30) and each one a user can enter a number and I have a total count at the bottom.
At present I have this:
$('input.qty').change(function() {
// Get the current total value
var total = $('#total');
// Update it with the changed input's value
total.val(parseInt(total.val()) + parseInt($(this).val()));
});
Example HTML:
<td><input type="text" class="qty" value="0" /></td>
<td><input type="text" class="qty" value="0" /></td>
<td><input type="text" class="qty" value="0" /></td>
<td><input type="text" id="total" value="0" /></td>
which adds fine first time, but when you start changing values it simply adds the new amount to the total rather then adding all the boxes up.
How can I sort this? Perhaps use the each attr somehow? Any suggestions would be much appreciated...
Adi.