I do a very rough check to see if the form is filled, if it is not there is a alert("Preencha todos os campos!");
, the problem is that when I click OK it reloads the page and thus clearing the form.
- I need the alert OK button not to clear the form.
- If possible, I want to redirect the fields that are not filled in.
JS
$('#btnCadMed').click(function(){
var nome = $("#txtNome").val();
var CRM = $("#txtCRM").val();
var idt = $("#txtIdentificador").val();
var esp = $("#txtEspecialidade").val();
if(nome == "" || CRM == "" || idt == "" || esp == ""){
alert("Preencha todos os campos!");
}else{
$("#txtNome").val("");
$("#txtCRM").val("");
$("#txtIdentificador").val("");
$("#txtEspecialidade").val("");
alert("Médico cadastrado com sucesso!");
}
});
Print the alert