Foros del Web » Programando para Internet » Javascript »

check all checkbox error w3c

Estas en el tema de check all checkbox error w3c en el foro de Javascript en Foros del Web. Tengo unas listas generadas mediante php y mysql dinamicamente, están divididas por familias, y he usado un javascript que me marca todos los checkbox de ...
  #1 (permalink)  
Antiguo 12/12/2011, 08:23
 
Fecha de Ingreso: octubre-2007
Mensajes: 130
Antigüedad: 16 años, 6 meses
Puntos: 2
check all checkbox error w3c

Tengo unas listas generadas mediante php y mysql dinamicamente, están divididas

por familias, y he usado un javascript que me marca todos los checkbox de esa

familia en concreto:
Código:
function selectCheckboxes(cat) { 
    var inputs = document.getElementsByTagName("input");
    var state;
    var tam = inputs.length;
	var i=0;
    while(inputs.length>i) {
        var obj = inputs[i];
         if ((obj.id == cat) && (obj.name!= cat)) {  
            state = obj.checked; // true or false 
            obj.checked = (state==true) ? false : true; 
        }
		
    i++;
	}
}

Este es el html que genero dinamicamente con php y mysql:

Código HTML:
<li>
            <h3 headerindex="1h" class="mypets openpet">laboral</h3>
            <div style="display: block;" contentindex="1c" class="thepet">
            <input name="66" onclick="selectCheckboxes(66);" type="checkbox"> 
            <span class="texto_menu_superior">Marcar todos [ laboral ]</span><br>
            <ul class="1_"> 
                            
              
            <li><br>
            <input name="242" id="66" value="Contratación" type="checkbox">
            <span class="texto_principal_peq"><strong>Contratación</strong>

            <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;It has survived not only five centuries, but also the leap into  electronic typesetting, remaining essentially unchanged. It was  popularised in the 1960s with the release of Letraset sheets containing  Lorem Ipsum passages, and more recently with desktop publishing software  like Aldus PageMaker including versions of Lorem Ipsum.<br></span>
            
        </li>
                          
              
            <li><br>
            <input name="243" id="66" value="Despidos" type="checkbox">
            <span class="texto_principal_peq"><strong>Despidos</strong>
            <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;It has survived not only five centuries, but also the leap into  electronic typesetting, remaining essentially unchanged. It was  popularised in the 1960s with the release of Letraset sheets containing  Lorem Ipsum passages, and more recently with desktop publishing software  like Aldus PageMaker including versions of Lorem Ipsum.<br></span>

            
        </li>
                          
              
            <li><br>
            <input name="244" id="66" value="Declaración renta" type="checkbox">
            <span class="texto_principal_peq"><strong>Declaración renta</strong>
            <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;It has survived not only five centuries, but also the leap into  electronic typesetting, remaining essentially unchanged. It was  popularised in the 1960s with the release of Letraset sheets containing  Lorem Ipsum passages, and more recently with desktop publishing software  like Aldus PageMaker including versions of Lorem Ipsum.<br></span>
            
        </li>
                          
              
            <li><br>

            <input name="245" id="66" value="prod3" type="checkbox">
            <span class="texto_principal_peq"><strong>prod3</strong>
            <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;It has survived not only five centuries, but also the leap into  electronic typesetting, remaining essentially unchanged. It was  popularised in the 1960s with the release of Letraset sheets containing  Lorem Ipsum passages, and more recently with desktop publishing software  like Aldus PageMaker including versions of Lorem Ipsum.<br></span>
            
        </li>
                          
              
            <li><br>
            <input name="246" id="66" value="prod4" type="checkbox">
            <span class="texto_principal_peq"><strong>prod4</strong>

            <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;descr<br></span>
            
        </li>
                          
              
            <li><br>
            <input name="248" id="66" value="Contratos" type="checkbox">
            <span class="texto_principal_peq"><strong>Contratos</strong>
            <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Lorem ipsum dolor<br></span>

            
        </li>
                         </ul>
             </div>
             </li></ul> 
Funciona perfectamente, pero el w3c no lo valida, me aparecen los siguientes errores:
Cita:
Line 163, Column 51: value of attribute "id" invalid: "6" cannot start a name

… <input type="checkbox" name="244" id="66" value="Declaración renta" />



It is possible that you violated the naming convention for this attribute. For

example, id and name attributes must begin with a letter, not a digit.
Error Line 163, Column 51: ID "66" already defined

… <input type="checkbox" name="244" id="66" value="Declaración renta" />
  #2 (permalink)  
Antiguo 12/12/2011, 08:32
Avatar de IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 9 meses
Puntos: 1012
Respuesta: check all checkbox error w3c

dos problemas
  • las id han de ser únicas
  • como te marca el error. las id han de empezar por un carácter alfabético
__________________
if(ViolenciaDeGénero) {alert('MUJER ASESINADA');}
  #3 (permalink)  
Antiguo 12/12/2011, 08:52
 
Fecha de Ingreso: octubre-2007
Mensajes: 130
Antigüedad: 16 años, 6 meses
Puntos: 2
Respuesta: check all checkbox error w3c

Hola IsabelM,

Gracias por tu respuesta. Si ese es el problema, necesitaría un javascript que no marque los checkbox por id. También he probado el nombre de las id con "cat_" delante para que no sean numéricos y en este caso no me funciona el javascript...

Etiquetas: checkbox, funcion, html, input, php, w3c, checked
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:18.