I decided to create a project in pure JavaScript without a database, very simple even just to study.
This system registers cars in a parking lot, so beauty, but I want the "Owner of the company" to enter the login and password, simulating a login.
Only the person types the login and does not go to another page, what am I doing wrong?
The javascript code is the one here:
var login = "[email protected]";
var senha = "1234";
var botao = document.querySelector("botaoEnviar");
botao.addEventListener("click", function(event){
event.preventDefault();
if(login == "" || login.indexOf('@')==-1 || login.indexOf('.')==-1){
console.log("E-mail errado");
alert("E-mail errado");
}
if(senha == ""){
console.log("Senha errada");
alert("Senha errada");
}else{
return false;
}
});
And the HTML is here:
<html>
<head>
<title>Estacionamento</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/login.css">
</head>
<body>
<form id="formLogin" action="index.html" method="post">
<div class="container">
<div class="row vertical-offset-100">
<div class="col-md-4 col-md-offset-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Entre com o seu login</h3>
</div>
<div class="panel-body">
<form accept-charset="UTF-8" role="form">
<fieldset>
<div class="form-group">
<input class="form-control" id="inputEmail" placeholder="E-mail" name="email" type="text">
</div>
<div class="form-group">
<input class="form-control" id="inputPass" placeholder="Password" name="password" type="password">
</div>
<div class="checkbox">
<label>
<input name="remember" type="checkbox" value="Remember Me"> Remember Me
</label>
</div>
<input class="btn btn-lg btn-success btn-block" id="botaoEnviar" type="submit" value="Login">
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
</form>
<script src="js/validarLogin.js"></script>
</body>
</html>
The error in the browser console:
validateLogin.js: 4 Uncaught TypeError: Can not read property 'addEventListener' of null at validarLogin.js: 4