You are viewing limited content. For full access, please sign in.

Question

Question

Field Calculation Problem With IE 11.0.9600

asked on March 19, 2015
//Calculate 2 Day Per Diem subtotal
  $('.perdiemsum').on('blur change', 'input', perdiemsumtotal);
    function perdiemsumtotal() {
        var s = 1;
        $('.perdiemsum input').each(function () {
            s *= parseNumber($(this).val());
        });
        $('.perdiemtotal input').val(s);
    }
    function parseNumber(n) {
        var f = parseFloat(n); //Convert to float number.
        return isNaN(f) ? 0 : f; //treat invalid input as 0;
    }
  //end calculate 2 Day Per Diem subtotal

I am working on a travel reimbursement form and have come across a calculation problem when using IE 11.0.9600. The calculation works correctly in the latest version of Firefox and Chrome.

Below is a screenshot of the fields and their values. The user should enter the Per Diem rate which is then calculated by the "Number of Days" field to give the "per diem subtotal". You can see in the screenshot that with IE 11 it is not calculating correctly. Below is also the JavaScript being used.

 

0 0

Answer

SELECTED ANSWER
replied on March 19, 2015

Try changing

$('.perdiemsum input').each(function () {

to

$('.perdiemsum input').filter(':visible').each(function () {

and see if that works around the IE issue.

0 0
replied on March 19, 2015

Alexander, that fixed it. What does that do exactly?

0 0
replied on March 19, 2015

In IE, there's an invisible button next to the single line input which causes values to be counted twice. That's why the end result is double what you'd expect. The javascript change is such that it only counts the value in the visible element.

0 0

Replies

You are not allowed to reply in this post.
replied on March 19, 2015

Have you tried it without 'blur' handler on line 2?

You are not allowed to follow up in this post.

Sign in to reply to this post.