0
I decided to create a project in pure Javascript without database, very simple even to study.
This system registers cars in a parking lot, even then beauty, but I want the home page " Company owner " enter the login and password, simulating a login same.
Only that the person enters the login and does not go to another page, what I’m doing wrong?
The javascript code is this one:
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 code 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>
<script src="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 browser console error:
validarLogin.js:4 Uncaught Typeerror: Cannot read Property 'addeventlistener' of null validateLogin.js:4
It did not work, tried both ways and continues the same thing, if I use getElementById the error in the console some, but does not send.
– Guilherme Ramos
Check now the reply @Guilhermeramos
– Ivo Silva
It worked, thank you very much!!!
– Guilherme Ramos