2


I have the next code:

jQuery(document).ready(function(){
    var total = 0;
    $('.commission_plan').each(function(){
        total = total + Math.floor($(this).val());
    });
    $('#payment_total_amount_hidden').val(total);
    $('#payment_total_amount').text('Total: '+total);

    $('.commission_plan').change(function() {
        total = 0;
        $('.commission_plan').each(function(){
            total = total + Math.floor($(this).val());
            $('#payment_total_amount_hidden').val(total);
            $('#payment_total_amount').text('Total: '+total);
        });
    });
});

All work fine in FireFox, but in IE, when I change input value, nothing happends. But if I do it the second time all OK. Can you help me? Sorry for my english.

John Hartsock
  • 85,422
  • 23
  • 131
  • 146
Alex Pliutau
  • 21,392
  • 27
  • 113
  • 143
  • Surely you'd have to put last total setters out of `each` function (deosn't solve your problem, but makes your code correct(er). – Robert Koritnik Nov 23 '10 at 18:00

2 Answers2

2

IE may not work the same way with change that Firefox does. You may try using something like keyup instead?

Also, you should move these lines outside of your each:

$('#payment_total_amount_hidden').val(total);
$('#payment_total_amount').text('Total: '+total);
jocull
  • 20,008
  • 22
  • 105
  • 149
2

This is a known (and annoying!) difference between Internet Explorer and other browsers. This highly ranked StackOverflow question should help you out.

Community
  • 1
  • 1
Tony Miller
  • 9,059
  • 2
  • 27
  • 46