Ver Mensaje Individual
  #2 (permalink)  
Antiguo 06/11/2004, 12:51
angsanchez
 
Fecha de Ingreso: octubre-2004
Ubicación: España
Mensajes: 894
Antigüedad: 20 años, 4 meses
Puntos: 3
Hola, mickeyy
Asumiendo que se vayan a llamar checkbox1, 2, etc lo puedes hacer así:

Código HTML:
<input type="button" value="Marcar todos" onClick="marcaTodos(this.form)">
 &nbsp; 
<input type="button" value="Invertir" onClick="invierte(this.form)"> 
Código:
function marcaTodos(formu) {
	for (i=1; i<formu.length; i++) {
		with (formu.elements[i]) {
			if ( name.indexOf('checkbox')==0 ) { checked = true }
		}
	}
}
function invierte(formu) {
	for (i=0; i<formu.length; i++) {
		with (formu.elements[i]) {
			if ( name.indexOf('checkbox')==0 ) { checked = !checked }
		}
	}
}
He intentado hacerlo mejor, usando la propiedad "type=checkbox" pero falla siempre en Mozilla y alguna vez en Explorer. Así que respetando los nombres, esta solución es buena.