1
Colleagues. I’m trying to clear the fields after Submit from a form, but I’m not getting it. Look:
$(document).ready(function() {
$("#resposta").ajaxStart(function(){
$(this).html("Mensagem sendo enviada, por favor aguarde...");
}
);
$("#submit").click(function() {
var nome = $("#nome").val();
var email = $("#email").val();
var assunto = $("#assunto").val();
var mensagem = $("#mensagem").val();
$.post('enviar.php', { nome: nome, email: email, assunto: assunto, mensagem: mensagem, contato: true }, function(data) {
if (data !== false) {
$("#resposta").html(data);
}else{
$("#nome").val("");
$("#email").val("");
$("#assunto").val("");
$("#mensagem").val("");
}
});
return false;
});
});
I tried it the following ways and it didn’t work either:
$("#form")[0].reset();
and
$("#form").trigger("reset");
Hello lvcs. Forgive me the question, because I am a layman in Jquery. Where do I include your code exactly? Thank you!
– user24136
All right, I’ll do it using your code.
– Leonardo
ready, it should work.
– Leonardo
Perfect lvcs...worked... thanks for the strength. Hug
– user24136
@ivcs, only a hint, when cleaning the fields use a selector within the scope of the form, or Voce will end up cleaning all the inputs of the screen, other thing, Voce can specify the types that will be cleaned without having to fill the name of the field Submit.
– Gabriel Rodrigues
@Gabrielrodrigues on the scope, I had done this, after the first edition of the answer (because I remembered it).. About type, it is much simpler to reset than to select by type, because we can have several types in the same form.
– Leonardo