0

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 blank 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
areid
  • 283
  • 2
  • 5
  • 14
  • Your code works fine for me [here](http://jsfiddle.net/Nalum/eG8SY/). Are you getting any errors on your console? – Nalum Jul 28 '11 at 09:36
  • Which field in particular? Do you get any arror in console? Could you post a snippet of your html too? – mamoo Jul 28 '11 at 09:37
  • @Nalum - None at all in chrome or firebug – areid Jul 28 '11 at 09:46
  • @mamoo - the fiddle above has the basics, it just totals fields with the classes '.add' and '.add_ex' – areid Jul 28 '11 at 09:47
  • @Nalum - Actually its saying Unexpected token ILLEGAL for the closing brackets after jQuery("#input_38").val(Total); – areid Jul 28 '11 at 10:20
  • 1
    SOLVED : Switched from Mac to PC notepad and found a bunch of random characters that needed deleted, it now works. – areid Jul 28 '11 at 10:56

1 Answers1

0

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.

Community
  • 1
  • 1
mamoo
  • 8,156
  • 2
  • 28
  • 38