One issue is that if a user deletes a number in an item field, it will not adjust the total until a new number is entered or a "0". Is there a way to change the script to recognize the deletion of a number as "0"?
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script>var jQ = $.noConflict(true);
// version 1
jQ( document ).ready(function() {
// Set Total_Items_Entered2 to read only
jQ('input[name="Total_Items_Entered2"]').prop('readonly', true);
// add the class sum to all inputs that we want to add
jQ('input[name^="GB"]').addClass( "sum" );
// on keyup check that the value isn't blank and it's numeric
jQ('input[name^="GB"]').on('keyup', function() {
if (jQ(this).val()!="" || jQ.isNumeric(jQ(this).val())){
// if input value is good fire the function
calc_dues();
}
});
// This is the calculate function
function calc_dues() {
var sum = 0;
jQ('.sum').each(function(){
if(jQ.isNumeric(this.value)){
sum += parseFloat(this.value);
jQ('input[name="Total_Items_Entered2"]').val(sum);
}
});
}
});</script>