From the description you gave me in your question, the code is running, but you forgot to show again the Divs you hid.
I believe that solves your problem:
$(document).ready(function()
{
$("#logarsist").click(function()
{
var usuario = $("#usera").val();
var password = $("#pass").val();
if(usuario == '')
{
$("#formulariousuario").html("Campo Obrigatório*");
$("#formulariousuario").show(); // também pode usar o fadeIn()
setTimeout(function()
{
$("#formulariousuario").hide(); // também pode usar o fadeOut()
}, 6000);
};
if(password == '')
{
$("#formulariopassword").html("Campo Obrigatório*");
$("#formulariopassword").show();
setTimeout(function()
{
$("#formulariopassword").hide();
}, 6000);
};
return false;
});
});
With a little more adaptation in your code you get some better results. See:
$(document).ready(function()
{
var timeout = null;
$("#logarsist").click(function()
{
var usuario = $("#usera").val();
var password = $("#pass").val();
if(usuario == '')
{
$("#formulariousuario").html("Campo Obrigatório*").show();
};
if(password == '')
{
$("#formulariopassword").html("Campo Obrigatório*").show();
};
// Cancele o timeout para evitar que ele oculte suas divs em momentos inesperados
clearTimeout(timeout);
timeout = setTimeout(function()
{
// Acrescente a classe "error" nas divs que deseja exibir as mensagens de erro.
$('.error').hide();
}, 6000);
// Você só deve retornar false se o form tiver erros ou for chamar outra função para realizar o envio do formulário.
return false;
});
});
Using a class selector and adding the class to your HTML, you avoid unnecessary code, and can have a more unified treatment.
Jquery also allows you to combine multiple methods into a single selector, reducing the processing of fetching the element again and reducing its code.
I don’t understand your question. Do you want your Submit to run only once or is it only running a single did? If the answer is the first alternative, just change ". click" by ". one" on the third line. If that’s not so, checked if the console displays any error message?
– Renan Cavalieri
it only runs once, no errors on console .
– Mateus Soares
actually it runs more than once, only the id with the messages only appear once
– Mateus Soares
It doesn’t happen because, after the first time, they’re already Hide(); ?
– Aline