function Validar() {
var nombre = document.querySelector('input[type=text]');
var email = document.querySelector('input[type=mail]');
if(nombre.value.length == "" )
{
alert('No puede qudar vacio');
return false;
if(email.value.length < 6)
{
alert('El nombre debe tener mas de 6 caracteres');
return false;
}
}
return true;
}
<form action="ejercicio_1.html" onsubmit=" return Validar()">
<div><input type="text" name="nombre" placeholder="Nombre y Apellido" /></div>
<div><input type="email" name="email" placeholder="Email" /></div>
<div><input type="password" name="clave" placeholder="Clave" /></div>
<div><input type="password" name="reclave" placeholder="Confirmar clave" /></div>
<hr />
<div>
<p>Sexo</p>
<label><input type="radio" name="sexo" value="masculino" /> Masculino</label>
<label><input type="radio" name="sexo" value="femenino" /> Femenino</label>
<label><input type="radio" name="sexo" value="whatever" /> Undefined</label>
</div>
<div>
<p>País / Provincia</p>
<select name="pais"></select>
<select name="provincia"></select>
</div>
<div>
<p>Intereses</p>
<label><input type="checkbox" name="programacion" value="programacion" /> Programacion</label>
<label><input type="checkbox" name="disenio" value="disenio" /> Diseño</label>
<label><input type="checkbox" name="musica" value="musica" /> Musica</label>
<label><input type="checkbox" name="literatura" value="literatura" /> Literatura</label>
<label><input type="checkbox" name="animacion" value="animacion" /> Animacion</label>
<p id="cant"></p>
</div>
<div><input type="submit" value="Enviar datos" /></div>
</form>
I am new to the validation of web forms. The validation of the if for the name can not be empty works, but basically I can not validate more than two things in a row. That is, all other validation if "step" on others.