Ver Mensaje Individual
  #4 (permalink)  
Antiguo 17/10/2011, 22:30
dfmex
 
Fecha de Ingreso: octubre-2008
Mensajes: 147
Antigüedad: 15 años, 6 meses
Puntos: 3
De acuerdo Respuesta: ¿Cómo puedo validar y verificar checkboxes?

Gracias por sus respuestas;

He finalmente logrado hacer la función que necesitaba (gracias a un poco de este foro, otro poco de otros foros).

Aquí dejo el código por si en un futuro alguien llegara a requerir algo similar.

Código Javascript:
Ver original
  1. <!-- En este ejemplo el formulario se llama "Tallas" -->
  2.  
  3. <script type="text/javascript" language="javascript">
  4.  
  5. function Checar(){
  6.     var elLength = document.Tallas.elements.length;
  7.     var Seleccionados = '';
  8.     var display = '';
  9.     var hids = '';
  10.     var b = 0;
  11.    
  12.     for (i=0; i<elLength; i++)
  13.     {
  14.         var type = Tallas.elements[i].type;
  15.         var nombre = Tallas.elements[i].name;
  16.         var valor = Tallas.elements[i].value;
  17.         var totales = document.Tallas.elements.length;
  18.        
  19.         if (type=="checkbox" && Tallas.elements[i].checked){
  20.            
  21.             if( (b != 0) && (b != totales) ){ var linea = "|"; }else{ var linea = ""; }
  22.            
  23.             if(linea == "|"){var agregar = "|" + valor + "&" + nombre;  var mostrar = ", " + nombre; var esconder = "|" + valor;}
  24.             else if(linea == ""){var agregar = "" + valor + "&" + nombre; var mostrar = "" + nombre; var esconder = "" + valor;}
  25.            
  26.             var Seleccionados = Seleccionados + agregar;
  27.             var display = display + mostrar;
  28.             var hids = hids + esconder;
  29.            
  30.             b++;
  31.         }
  32.         else {  }
  33.        
  34.     }
  35.    
  36.     if(b == 0){ alert('No se ha seleccionado NADA'); }
  37.     else{
  38.     alert(Seleccionados);
  39.     alert(display);
  40.     alert(hids);
  41.     }
  42. }
  43.  
  44. </script>