0

I want to define 4 arrays with specific postal codes for each location, and then based on a postal code (value of a user-submitted form) I want to redirect user to a new location.

I have no idea what I am doing wrong (I am not a coder).

I am trying to do something like this, but it doesn't work:

<!DOCTYPE html>
<script>
function sprawdzKody() {

const mokotow = ["00-807", "00-808", "00-809"];
const ursynow = ["01-807", "01-808", "01-809"];
const targowek = ["02-807", "02-808", "02-809"];
const wesola = ["03-807", "03-808", "03-809"];

var kodPocztowy = document.getElementById("kodPocztowy").value;

if(mokotow.includes(kodPocztowy)){ 
   window.location.href = "https://mokotow.geishasushi.pl";
} 
else if(ursynow.includes(kodPocztowy)){ 
   window.location.href = "https://ursynow.geishasushi.pl";
} 
else if(targowek.includes(kodPocztowy)){ 
   window.location.href = "https://targowek.geishasushi.pl";
} 
else if(wesola.includes(kodPocztowy)){ 
   window.location.href = "https://ursynow.geishasushi.pl";
} 
else { 
  window.location.href = "http://geishasushi.pl/jestes-poza-rejonem";
}
}
</script>


<form onsubmit="return sprawdzKody();" class="kod-pocztowy">
    <label for="kodPocztowy"> Kod Pocztowy</label><br>
    <input type="text" id="kodPocztowy" name="kodPocztowy"><br>
    <input type="submit" value="Znajdź Twoją restaurację">
</form>
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • *Offtopic advice*: always develop like the guy who will inherit your code is not from your country, but he exactly knows where you live. PS: after a first glimpse, I see no issue currently in your code. When you say: *"It doesn't work"* — what do you mean exactly? – Roko C. Buljan Apr 04 '22 at 00:49
  • Why do you use twice the `https://ursynow.geishasushi.pl` ? – Roko C. Buljan Apr 04 '22 at 00:57
  • Why do you use `http://geishasushi.pl` instead of `https`? – Roko C. Buljan Apr 04 '22 at 01:01

1 Answers1

0

Check this link below: How do I redirect with JavaScript?

It will help you to understand the redirect in JS and correct your code.

user2668276
  • 67
  • 13