total and prev value jquery
HTML
<input type="text" name="a" value="0">
<br>
<input type="text" name="a" value="0">
<br>
<input type="text" name="a" value="0">
<br>
<input type="text" name="a" value="0">
<br>
<input type="text" name="a" value="0">
<br>
<input type="text" name="a" value="0">
<br>
<input type="text" name="a" value="0">
<br>
JavaScript
$(document).on('change', 'input', function () {
var value = 0;
$('input').each(function () {
var i = parseInt($(this).val());
if (!isNaN(i)) {
value += i;
}
});
console.log(value);
$('#total').val(value);
});
console.log('new:' + $(this).val() + ' old:' + $(this).data('oldValue'));
$(this).data('oldValue', $(this).val());
});
$(':input').each(function () {
$(this).data('oldValue', $(this).val());
});