jQuery - Input field calculation not working in Chrome and Safari
I have a form with fields that are automatically totaled when values are added, it works fine in ie 6,7 +8 and FF but the field is blan开发者_如何学Ck in Safari and Chrome - any ideas??
// total income
jQuery(document).ready(function(){
jQuery("input.add").change(function () {
var sum = 0;
jQuery('.add').each(function() {
var Total = sum += Number(jQuery(this).val());
jQuery("#input_38").val(Total);
});
}); <--- Chrome has a problem with this 'Unexpected token ILLEGAL'
// total expenditure
jQuery("input.add_ex").change(function () {
var sumEx = 0;
jQuery('.add_ex').each(function() {
var TotalEx = sumEx += Number(jQuery(this).val());
jQuery("#input_70").val(TotalEx);
});
});
//grand total
jQuery("input.add_ex").change(function () { // when total expenditure field changes
var totalInc = Number(jQuery("#input_38").val()); // store total income as var
var totalExp = Number(jQuery("#input_70").val()); // store total expenditure as var
jQuery("#input_75").val(totalInc - totalExp); // change grand total
});
});//end
Since the example of Nalum is working maybe some hidden characters are messing up your script.
Try to use JSLint to see if it spots the same problem, and try to remove some spaces in that line.
edit:
I found a similar question here.
精彩评论