I'm trying to create a simple validation of two fields, where I only check if there is a value or not, but the second if only runs after passing the first one.
I wanted the two to be fired at the same time, what would be the most practical way to do this?
Here's the example of my current validation:
$(document).ready(function(){
$('#formLogin').on('submit', function(e){
if($('#txtLogin').val() == ''){
e.preventDefault();
if (!$('.err-text').length) {
$('#txtLogin').closest('.login__column').append('<span class="err-text">*E-mail incorrecto.
<br>Ingresa un E-mail válido para participar.</span>');
}
} else {
$('#txtLogin').next('.err-text').remove();
}
if($('#txtSenha').val() == ''){
e.preventDefault();
if (!$('.err-text').length) {
$('#txtSenha').closest('.login__column').append('<span class="err-text">*Contraseña incorrecta.
<br>Ingresa una contraseña válida para participar.</span>');
}
} else {
$('#txtSenha').next('.err-text').remove();
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><formid="formLogin">
<div class="login__column">
<input type="text" id="txtLogin">
</div>
<div class="login__column">
<input type="text" id="txtSenha">
</div>
<button type="submit">Enviar</button>
</form>