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)">
<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.