Ver Mensaje Individual
  #14 (permalink)  
Antiguo 18/11/2016, 07:52
mpozo
 
Fecha de Ingreso: noviembre-2015
Mensajes: 231
Antigüedad: 8 años, 5 meses
Puntos: 86
Respuesta: funcion con datos dinamicos

Es algo como esto
Código Javascript:
Ver original
  1. <!DOCTYPE html>
  2. <html dir="ltr" lang="es-es">
  3.     <head>
  4.         <title></title>
  5.         <meta charset="utf-8">
  6.         <style>
  7.  
  8.         </style>
  9.         <script>
  10.  
  11.         </script>
  12.     </head>
  13.     <body>
  14.  
  15.         <form method="post" action="" id="f">
  16.  
  17.             <label for="nublado">nublado</label><br/>
  18.             poco <input type="radio" name="nublado" value="poco"><br/>
  19.             normal <input type="radio" name="nublado" value="normal"><br/>
  20.             mucho <input type="radio" name="nublado" value="mucho"><br/>
  21.              
  22.             <br/>
  23.             <br/>
  24.              
  25.             <label for="lloviendo">lloviendo</label><br/>
  26.             poco <input type="radio" name="lloviendo" value="poco"><br/>
  27.             normal <input type="radio" name="lloviendo" value="normal"><br/>
  28.             mucho <input type="radio" name="lloviendo" value="mucho"><br/>
  29.  
  30.             <br/>
  31.             <br/>
  32.  
  33.             <label for="llovi">llovi</label><br/>
  34.             poco <input type="radio" name="llovi" value="poco"><br/>
  35.             normal <input type="radio" name="llovi" value="normal"><br/>
  36.             mucho <input type="radio" name="llovi" value="mucho"><br/>
  37.  
  38.             <input type="submit" id="s" value="go!!" />
  39.          
  40.         </form>
  41.  
  42.  
  43.         <script>
  44.         document.querySelector('#f').addEventListener('submit', function(event) {validaData(event)});
  45.  
  46.         function validaData(evt) {
  47.  
  48.             var labels = document.querySelectorAll('form label').length,
  49.             check = 0;
  50.  
  51.             [].forEach.call(document.querySelectorAll('form input[type="radio"]'), function(e) {
  52.  
  53.                 if (e.checked) ++check;
  54.             });
  55.  
  56.             if (labels > check) {
  57.  
  58.                 evt.preventDefault();
  59.                 console.log('rellena todos los grupos');
  60.  
  61.             }
  62.         }
  63.         </script>
  64.     </body>
  65. </html>