Ver Mensaje Individual
  #13 (permalink)  
Antiguo 11/02/2009, 16:27
Avatar de SPAWN3000
SPAWN3000
 
Fecha de Ingreso: marzo-2008
Ubicación: Bogota
Mensajes: 858
Antigüedad: 17 años
Puntos: 15
Respuesta: checked a todos los checkbox

Yo lo que proponía era esto...

Código:
<html>
<head>
<script>
function marcaAllCheckBox(objForm){
//Es mejor separar la variable y no estarla analizando en el for, aumenta el rendimiento
var miform=document.forms[objForm].elements.length;
k = miform-1;
miform = Math.floor(miform/2);
	for (i=0;i<=miform;i++){
		if(document.forms[objForm].elements[i].type=="checkbox"){
			document.forms[objForm].elements[i].checked=true;
		}
		if(document.forms[objForm].elements[k].type=="checkbox"){
			document.forms[objForm].elements[k].checked=true;
		}
		alert('Posicion:'+k);
		k=k-1;
	}
}
</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
<input type="checkbox" name="todos" onclick="marcaAllCheckBox('form1')"/><br/>
<input type="checkbox" name="algo1"/><br/>
<input type="checkbox" name="algo2"/><br/>
<input type="checkbox" name="algo3"/><br/>
<input type="checkbox" name="algo4"/><br/>
<input type="checkbox" name="algo5"/><br/>
<input type="checkbox" name="algo6"/><br/>
<input type="checkbox" name="algo7"/><br/>
<input type="checkbox" name="algo8"/><br/>
<input type="checkbox" name="algo9"/><br/>
<input type="checkbox" name="algo10"/><br/>
<input type="checkbox" name="algo11"/><br/>
<input type="checkbox" name="algo12"/><br/>
<input type="checkbox" name="algo13"/><br/>
<input type="checkbox" name="algo14"/><br/>
<input type="checkbox" name="algo15"/><br/>
<input type="checkbox" name="algo16"/><br/>
<input type="checkbox" name="algo17"/><br/>
<input type="checkbox" name="algo18"/><br/>
<input type="checkbox" name="algo19"/><br/>
<input type="checkbox" name="algo20"/><br/>
</body>
</html>
Se recorre en ambos sentidos, también sería bueno agregar id's y no estar colocando el if...