title: Cannot redirect using javascript
body: <p>I have a page that verifies credit card credentials. It's all well and good until I need to redirect the user to a another page.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function vNumarCard(numar)
  {
      console.log(numar);
    var cardno = /^(?:4[0-9]{12}(?:[0-9]{3})?)$/;
    if(!numar.match(/^(?:4[0-9]{12}(?:[0-9]{3})?)/))
          {
        return false;
          }
        else
          {
          
          return true;
          }
  }
  
  function vDataExp(data){
      console.log(data);
      if(!data.match(/(0[1-9]|1[0-2])[/][0-9]{2}/)){
          
          return false;
      }
      else{
          
          var d = new Date();
          var anCurent = d.getFullYear();
          var lunaCurenta = d.getMonth() + 1;
          var parti = data.split('/');
          var an = parseInt(parti[1], 10) + 2000;
          var luna = parseInt(parti[0], 10);
           if (an &lt; anCurent || (an == anCurent &amp;&amp; luna &lt; lunaCurenta)) {
               alert("Card expirat!")
              return false;
           }
           
           return true;
  
  }
  }
  
  function vCVC(cvc){
      console.log(cvc);
      if(!cvc.match(/[0-9][0-9][0-9]/)){
          
          return false;
      }
      else{
          return true;
      }
  }
  
  function verCard(numar,data,cvc){
      if(vNumarCard(numar)==true&amp;&amp;vDataExp(data)==true&amp;&amp;vCVC(cvc)==true){
          alert('inside if');
          location.href = '/success.html';
      }
      else if(vNumarCard(numar)==false) alert("Numarul cardului este invalid!");
          else if(vDataExp(data)==false) alert("Data expirarii este invalida");
              else alert("CVC incorect!");
  }
  
  function verDate(){
      var numar = document.getElementsByName("numarCard")[0].value;
      var data = document.getElementsByName("dataExp")[0].value;
      var cvc = document.getElementsByName("codCVC")[0].value;
  
      verCard(numar,data,cvc);
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="ro"&gt;
  &lt;head&gt;
   &lt;title&gt;Cumpara&lt;/title&gt;
  &lt;meta charset="utf-8"&gt;
   &lt;link rel="stylesheet" type="text/css" href="node_modules/bootstrap/scss/bootstrap.css"&gt;
   
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;nav class="navbar navbar-expand-sm bg-dark navbar-dark justify-content-center"&gt;
      &lt;ul class="navbar-nav"&gt;
       &lt;li class="nav-item"&gt;
        &lt;a class="nav-link" href="index.html"&gt;Acasă&lt;/a&gt;
       &lt;/li&gt;
       &lt;li class="nav-item"&gt;
        &lt;a class="nav-link" href="modele.html"&gt;Modele&lt;/a&gt;
       &lt;/li&gt;
       
       &lt;li class="nav-item"&gt;
        &lt;a class="nav-link" href="galerie.html"&gt;Galerie&lt;/a&gt;
       &lt;/li&gt;
       &lt;li class = "nav-item"&gt;
        &lt;a href="cos.html" class = "nav-link"&gt;
                 &lt;span class="glyphicon"&gt;&amp;#128722;&lt;/span&gt;
               &lt;/a&gt;
       &lt;/li&gt;
      &lt;/ul&gt;
      
   &lt;/nav&gt;
  
  &lt;div class="container"&gt;
   &lt;div class="row"&gt;
    &lt;div class="col-sm-4"&gt;
    &lt;/div&gt;
    &lt;div class="col-sm-4"&gt;
     &lt;h2 style="text-align: center;"&gt;Cumpara produsele selectate&lt;/h2&gt;
     &lt;form method="POST"&gt;
      
      &lt;div class="form-group"&gt;
       &lt;label for="email"&gt;
        Email:
       &lt;/label&gt;
       &lt;input type="email" name="email" class="form-control" placeholder="Email"&gt;
       
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
       &lt;label for="numeCumparator"&gt;
        Nume:
       &lt;/label&gt;
       &lt;input type="text" name="numeCumparator" class="form-control" placeholder="Nume"&gt;
       
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
       &lt;label for="numarCard"&gt;
        Numar Card:
       &lt;/label&gt;
       &lt;input type="text" name="numarCard" class="form-control" placeholder="1234 1234 1234 1234"&gt;
       
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
       &lt;label for="dataExp"&gt;
        Data de expirare:
       &lt;/label&gt;
       &lt;input type="text" name="dataExp" class="form-control" placeholder="ll/aa"&gt;
       
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
       &lt;label for="codCVC"&gt;
        CVC:
       &lt;/label&gt;
       &lt;input type="text" name="codCVC" class="form-control" placeholder="CVC"&gt;
       
      &lt;/div&gt;
      &lt;button name="cumpara" type="submit" class="btn btn-success btn-lg btn-block" onclick="verDate();"&gt;Cumpara&lt;/button&gt;
     &lt;/form&gt;
    &lt;/div&gt;
    &lt;div class="col-sm-4"&gt;&lt;/div&gt;
   &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;script src="node_modules/jquery/dist/jquery.min.js"&gt;&lt;/script&gt;
   &lt;script src="node_modules/bootstrap/dist/js/bootstrap.min.js"&gt;&lt;/script&gt;
   &lt;script src="scripturi/cumpara.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Every function works corectly, I checked each of them and I used the alert to see if the if works and it does. I used the same method on other pages and it works well but location.href doesn't work. I have also tried with document.location.href and window.location but I get the same result. What actually happens is that the same page gets reloaded instead of getting redirected.</p>