Follow link with Enter based on user input

0

With the help of the community, I created a file to redirect a user who typed his login to a webpage that receives the user this way:

link

The problem is that usually the user presses Enter when typing the text, so I tried to adjust the code so that pressing this key was redirected, but apparently the link is not receiving the variable.

Could you help me by pressing Enter or clicking Login after entering your login, the user is directed?

Here is my code:

<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

<title>Redirecionamento</title>
<div class="page-margin"></div>
<br>
<br>
<div align="center" class="welcome-form-div">
  <div class="welcome-form">
    <div class="html-logo">
      <i class="icon-comments-alt"></i> Insira os números do seu
      <br><b>login</b> <i>ou</i> <b>CPF</b> e clique em Entrar
      <br>
      <br>
    </div>

    <input type="text" id="username" name="username" size="20">
    <input type="button" id="BotaoLogin" value="Entrar" onClick="redirecionar()">
</div>


<script language="javascript">

var username = document.getElementById("username");

username.addEventListener("keydown", function(e) {
  if (e.keyCode == 13) {
    redirecionar(e);
  }
});

function redirecionar() {
  if (username != "") {
    window.location = "https://site.com.br/usuario"+username+"&empresa";
  }
}
</script>
    
asked by anonymous 31.10.2017 / 16:02

1 answer

0
function redirecionar() {
  var username = document.getElementById("username").value;
  if (username != "") {
    window.location = "https://site.com.br/usuario"+username+"&empresa";
  }
}

I'm missing the value of the element.

    
31.10.2017 / 16:24