0

I have a quite extent code, so I'm gonna post the chuck that matters, and try to explain what's going on. I found the exact piece which is disabling my whole jQuery for IE. I read many posts and checked about problems like the use of old libraries, sets of IE, but I couldn't find an answer.

This code runs smoothly and achieves the result: every time an input is made for any input of type number, it fires an alert.

$(document).ready(function() { 
    $("input[type=number]").on('input', function(){
      alert("123")
    });
 });

Since the selector is working (tested in the previous example), after inputting any of the fields, I try to sum up all the number inputs from my form and text the result. Then, it's blocking my whole code.

$(document).ready(function() { 
   $("input[type=number]").on('input', function(){
     let tot = 0;
     $("form#form-residential :input[type='number']").each((i, el) => tot += parseInt(el.value || 0, 10));
     $('.total-residential').text(tot);
     });
  });

Has anyone ever experienced something similar?

igortp
  • 179
  • 1
  • 14

1 Answers1

1

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

The arrow function, which is unsupported in every version of IE according to MDN, is causing the error.

You could replace it with an anonymous function declaration function(i, el){ tot += parseInt(el.value || 0, 10); }

Holden Rohrer
  • 586
  • 5
  • 16
  • Hi! Please read through the [help]. This is an **often**-repeated duplicate question. On SO, instead of posting new answers, which just clutters things up and leads to a mess of different (sometimes contractory) answers in lots of different places, we close duplicates and point to the original question that it duplicates. – T.J. Crowder May 16 '20 at 17:20
  • Would be the solution something like this? `$(document).ready(function() { $("input[type=number]").on('input', function(){ let tot = 0; var x = function(i, el){ tot += parseInt(el.value || 0, 10); } $("form#form-residential :input[type='number']").each(x); $('.total-residential').text(tot); }); });` – igortp May 16 '20 at 17:39
  • Working! Amazing @Holden Rohrer – igortp May 16 '20 at 17:49