Javascript forwarding does not work with external script

Asked

Viewed 125 times

0

Javascript forwarding does not work with external script.

I have a page with the following code:

<input type="text" name="login" id="login">
<input type="password" name="senha" id="senha">
<button type="button" id="btnEntrar">Entrar</button>
<script src="js/functions-index.js"></script>

On my page functions-index.js:

        var btnEntrar = document.getElementById('btnEntrar');
        var login = document.getElementById('login');
        var senha = document.getElementById('senha');


        btnEntrar.addEventListener('click', function(){

          if(login.value ==''){
            alert("Preencha o campo email");
          }
          else if(login.senha == ''){
            alert("Preencha o campo senha");
          }
          else if(login.senha === '123'){
                console.log(login.value);
                location.href = "pag2.html";


          }


 });

However, redirecting does not work.Not even with href, location, replace and etc No error is returned

1 answer

0


HTML

<input type="text" name="login" id="login">
<input type="password" name="senha" id="senha">
<button type="button" id="btnEntrar">Entrar</button>
<script src="js/functions-index.js"></script>

Javasscript

Script left to close with });

Alter login.senha for senha.value

    var btnEntrar = document.getElementById('btnEntrar');
    var login = document.getElementById('login');
    var senha = document.getElementById('senha');


   btnEntrar.addEventListener('click', function(){

      if(login.value ==''){
        alert("Preencha o campo email");
      }
      else if(senha.value == ''){
        alert("Preencha o campo senha");
      }
      else if(senha.value === '123'){
            //console.log(login.value);
            alert(login.value);
            location.href = "pag2.html";


      }
  });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.