Tim
Tim

Reputation: 137

Javascript code doesn't work on Safari

I have a script running on my index.html page. It works perfectly for other browsers except Safari. Any idea why? My script check the input of the User and see if it matches any of the postal codes in the array. If it matches it'll redirect user to a new page. If it doesn't match, i'll show a hidden message.

<script>
  // CHECK IF USER WITHIN DELIVERY AREA
  function checkAnswer(){
        var postalCode = ["V5K", "V5M","V5R","V5S","V5L"]
    var response = document.getElementById('answer').value;
    for (var i = 0; i < postalCode.length; i++) {
      if (response.substring(0,3).toUpperCase() == postalCode[i]) {
        location = '/postal-code-area';
        break 
      } 
      if (postalCode.every(elem => elem !== response.substring(0,3).toUpperCase())) {
            $("#postal-code-not-found").css("visibility","visible");
            setTimeout(function() {
                $("#postal-code-not-found").css("visibility","hidden");
            },3000);
      }
    }
    return false;
  }
</script>

Upvotes: 0

Views: 306

Answers (1)

toanpt
toanpt

Reputation: 66

Maybe you can change: $("#postal-code-not-found").css("visibility","visible"); setTimeout(function() { $("#postal-code-not-found").css("visibility","hidden"); },3000);

to: $("#postal-code-not-found").css("display","block"); setTimeout(function() { $("#postal-code-not-found").css("display","none"); },3000);

Upvotes: 1

Related Questions