Advertisement
AlejandroGY

Untitled

Oct 6th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5.     <meta charset="UTF-8">
  6.     <title>Datos del usuario</title>
  7.  
  8.     <script>
  9.         let formulario = document.forms['formulario'];
  10.         window.onload = iniciar;
  11.  
  12.         function iniciar( ) {
  13.             document.getElementById('btn').addEventListener('click', validar, false);
  14.         }
  15.  
  16.         function validaNombre( ) {
  17.             let elemento = document.getElementById('nombre');
  18.            
  19.             if (elemento.value == "") {
  20.                 alert("Llena el campo nombre!");
  21.                 return false;
  22.             }
  23.             return true;
  24.         }
  25.  
  26.         function validaApellidoPaterno( ) {
  27.             let elemento = document.getElementById('apPat');
  28.            
  29.             if (elemento.value == "") {
  30.                 alert("Llena el campo apellido paterno!");
  31.                 return false;
  32.             }
  33.             return true;
  34.         }
  35.  
  36.         function validaApellidoMaterno( ) {
  37.             let elemento = document.getElementById('apMat');
  38.            
  39.             if (elemento.value == "") {
  40.                 alert("Llena el campo apellido materno!");
  41.                 return false;
  42.             }
  43.             return true;
  44.         }
  45.  
  46. /*********************** Fecha *********************/
  47.         function validaFecha( ) {
  48.             var fecha = "";
  49.             document.getElementById('fecha').addEventListener('change', function( ) {
  50.                 fecha = this.value;
  51.                 console.log(fecha);
  52.             });
  53.  
  54.             if (fecha == "") {
  55.                 alert("Selecciona un fecha!");
  56.                 return false;
  57.             }
  58.             return true;
  59.         }
  60. /******************* Fin Fecha *********************/
  61.  
  62.         function validar(e) {
  63.             if (validaNombre( ) && validaApellidoPaterno( ) && validaApellidoMaterno( ) && validaFecha( ) && confirm("Desea continuar?")) {
  64.                 return true;
  65.             } else {
  66.                 e.preventDefault( );
  67.                 return false;
  68.             }
  69.         }
  70.     </script>
  71.  
  72. </head>
  73. <body>
  74.  
  75.     <form action="contacto.html" name="formulario" id="formulario" method="get">
  76.         <fieldset>
  77.         <p>Nombre: <input type="text" name="nombre" id="nombre"></p>
  78.         <p>Apellido Paterno: <input type="text" name="apPat" id="apPat"></p>
  79.         <p>Apellido Materno: <input type="text" name="apMat" id="apMat"></p>
  80.         <p>Fecha de Nacimiento: <input type="date" name="fecha" id="fecha"></p>
  81.         <button type="button" name="btn" id="btn">Siguiente</button>
  82.         </fieldset>
  83.     </form>
  84.  
  85. </body>
  86. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement