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
  • 82,242
  • 22
  • 125
  • 144
Alex Pliutau
  • 20,640
  • 26
  • 107
  • 142
  • 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
  • 18,749
  • 20
  • 100
  • 147
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
  • 8,919
  • 2
  • 26
  • 46