Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Datos del usuario</title>
- <script>
- let formulario = document.forms['formulario'];
- window.onload = iniciar;
- function iniciar( ) {
- document.getElementById('btn').addEventListener('click', validar, false);
- }
- function validaNombre( ) {
- let elemento = document.getElementById('nombre');
- if (elemento.value == "") {
- alert("Llena el campo nombre!");
- return false;
- }
- return true;
- }
- function validaApellidoPaterno( ) {
- let elemento = document.getElementById('apPat');
- if (elemento.value == "") {
- alert("Llena el campo apellido paterno!");
- return false;
- }
- return true;
- }
- function validaApellidoMaterno( ) {
- let elemento = document.getElementById('apMat');
- if (elemento.value == "") {
- alert("Llena el campo apellido materno!");
- return false;
- }
- return true;
- }
- /*********************** Fecha *********************/
- function validaFecha( ) {
- var fecha = "";
- document.getElementById('fecha').addEventListener('change', function( ) {
- fecha = this.value;
- console.log(fecha);
- });
- if (fecha == "") {
- alert("Selecciona un fecha!");
- return false;
- }
- return true;
- }
- /******************* Fin Fecha *********************/
- function validar(e) {
- if (validaNombre( ) && validaApellidoPaterno( ) && validaApellidoMaterno( ) && validaFecha( ) && confirm("Desea continuar?")) {
- return true;
- } else {
- e.preventDefault( );
- return false;
- }
- }
- </script>
- </head>
- <body>
- <form action="contacto.html" name="formulario" id="formulario" method="get">
- <fieldset>
- <p>Nombre: <input type="text" name="nombre" id="nombre"></p>
- <p>Apellido Paterno: <input type="text" name="apPat" id="apPat"></p>
- <p>Apellido Materno: <input type="text" name="apMat" id="apMat"></p>
- <p>Fecha de Nacimiento: <input type="date" name="fecha" id="fecha"></p>
- <button type="button" name="btn" id="btn">Siguiente</button>
- </fieldset>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement