I have the following code and I would like to know how to make após o click no button enviar
appear the message Login successfully! and after 3 seconds the form is sent:
function validarLogin(strLogin,strSenha) {
if(strLogin == "") {
document.getElementById('login').style.borderColor = "red";
document.frmLogin.txtLogin.focus();
document.getElementById('strong1').style.display = "block";
document.getElementById('sucesso').style.visibility = "hidden";
return false;
}
else if(strSenha == "") {
document.getElementById('senha').style.borderColor = "red";
document.frmLogin.txtSenha.focus();
document.getElementById('strong2').style.display = "block";
document.getElementById('sucesso').style.visibility = "hidden";
return false;
}
else {
document.getElementById('sucesso').style.visibility = "visible";
return true;
}
}
function input1() {
var strLogin = document.getElementById('login').value;
if(strLogin !== "") {
document.getElementById('strong1').style.display = "none";
document.getElementById('login').style.borderColor = "green";
}
else {
return false;
}
}
function input2() {
var strSenha = document.getElementById('senha').value;
if(strSenha !== "") {
document.getElementById('strong2').style.display = "none";
document.getElementById('senha').style.borderColor = "green";
}
else {
return false;
}
}
function delay() {
var form = document.getElementById('form');
form.submit();
return validarLogin();
}
function forml() {
var form = document.getElementById('form');
form.addEventListener('submit', function(e) {
e.preventDefault();
setTimeout(delay, 2000);
});
}
#box {
background-color: #28B2A1;
padding: 10px;
border-radius: 6px;
margin-top: 25%;
}
strong {
display: none;
color: red;
}
.btn {
margin: 0 auto;
}
#sucesso {
visibility: hidden;
color: #28B2A1;
background-color: #fff;
padding: 10px;
border-radius: 6px;
}
samp{
font-weight: bolder;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-4 col-xs-12" id="box">
<h4 class="text-center" id="sucesso">Login realizado com sucesso!</h4>
<form name="frmLogin" id="form" action="validar_login_js.html" method="post" onsubmit="return validarLogin(txtLogin.value,txtSenha.value);">
<samp><label for="login">LOGIN</label></samp>
<input type="text" class="form-control" id="login" name="txtLogin" value="Fulano" onfocus="this.value='';" onblur="input1()">
<strong id="strong1">Preencha corretamente o campo Login!</strong id="strong1"><br>
<samp><label for="senha">SENHA</label></samp>
<input type="password" class="form-control" id="senha" name="txtSenha" value="123456" onfocus="this.value='';" onblur="input2()">
<strong id="strong2">Preencha corretamente o campo Senha!</strong><br><br>
<p class="text-center"><input type="submit" class="btn btn-warning" name="btnEnviar" value="Enviar" id="enviar"> <input type="reset" class="btn btn-secondary" name="btnLimpar" value="Resetar"></p>
</form>
</div>
</div>
</div>