1
I’m trying to use a validation in a form I have using Javascript, but it’s not working very well, what I’m trying to do is this:
I defined a div like this:
<style type="text/css">
.msg-erro{ color: red; }
</style>
In my input I put a <span> thus:
<div class="col-md-12 col-sm-12">
<label>Empresa *</label>
<input type="text" id="Empresa" name="Empresa" value="" class="form-control required">
<span class='msg-erro msg-empresa'></span>
</div>
And at the time of recording the record is like this:
// RECUPERA VARIÁVEL DO CAMPO HIDDEN
var IdCandidato = $("#pk").val();
// RESGATANDO VALORES
var Empresa = $("#Empresa").val();
var Cargo = $("#Cargo").val();
var DataEntrada = $("#DataEntrada").val();
var DataSaida = $("#DataSaida").val();
var UltimoSalario = $("#UltimoSalario").val();
var Atividades = $("#Atividades").val();
var contErro = 0;
/* Validação do campo nome */
MsgEmpresa = document.querySelector('.msg-empresa');
if (Empresa.value == ""){
MsgEmpresa.innerHTML = "Favor preencher a Empresa";
MsgEmpresa.style.display = 'block';
contErro += 1;
} else {
MsgEmpresa.style.display = 'none';
}
if(contErro > 0){
evt.preventDefault();
}
But the message is not being displayed and the form is submitted.
The layout of the form looks like this:

Your feedback is very important for people who want to help!. That’s why it’s important to mark the response that helped you in your project.
– Cristiano Gilberto João
Hello @Cristianogilbertojoão, thanks for the tip, but none of the answers helped me in what I need, even giving me a good direction.
– adventistapr