guys! I'll be brief, I'm doing a basic form in HTML of the type "Register here", some input I throw them with attribute 'required', but when I try it they do not work for me. I leave an example.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/estilos.css">
<title>Regístrese aquí</title>
</head>
<body>
<form action="Registrar.php" class="formulario">
<h1 class="titulo">Regístrese Aquí</h1>
<div>
<label for="nombres">Nombres: </label>
<input type="text" name="nombres" id="nombres" required>
</div>
<div>
<label for="apellidos">Apellidos: </label>
<input type="text" name="apellidos" id="apellidos" >
</div>
<div>
<label for="correo">Correo: </label>
<input type="email" name="correo" id="correo" required>
</div>
<div>
<label for="estadoCivil">Estado Civil</label>
<select name="estadoCivil" id="estadoCivil">
<option value="0"></option>
<option value="1">Soltero(a)</option>
<option value="2">Casado(a)</option>
<option value="3">Union Libre</option>
<option value="4">Viudo(a)</option>
</select>
</div>
<div>
<label for="genero">Genero: </label>
Hombre <input type="radio" name="genero value="H>
Mujer <input type="radio" name="genero value="M>
</div>
<div>
<label for="password">Password: </label>
<input type="password" name="password" id="password" required>
</div>
<div>
<label for="password1">Confirmar Password: </label>
<input type="password1" name="password1" id="password1" required>
</div>
<div>
<input type="button" value="Enviar" id="enviar" class="boton">
<input type="reset" class="boton">
</div>
<div class="mensajes">
</div>
</form>
<script src="js/app.js"></script>
</body>
</html>
JavaScript for the type button
enviar=document.getElementById("enviar");
enviar.onclick=validarDatos;
function validarDatos () {
var elemento =document.getElementById("correo");
if (elemento.checkValidity() ==false && elemento.required){
//document.getElementById("mensajes").innerHTML='<p>Debe ingresar un ${elemento.id} valido</p>';
document.getElementById("mensajes").innerHTML="<p>Debe ingresar un "+elemento.id +" valido</p>";
}
}