Funciona!
Mira el ejemplo:
Código PHP:
<html>
<head>
<title>Untitled</title>
<script>
cambio=-1
function marcar(este){
cambio=-cambio;
todos=document.forms[0].elements.length;
este.value=(cambio==1)?"Desmarcar todos":"Marcar todos";
for(a=0;a<todos;a++){
campo=document.forms[0].elements[a];
if (campo.type=="checkbox"){
campo.checked=(cambio==1)?true:false;
}
}
}
</script>
</head>
<body>
<form action="javascript:alert('Enviando');">
<input type="checkbox" name="pepe" value="1">pepe<br>
<input type="checkbox" name="pepe" value="1">pepe<br>
<input type="checkbox" name="pepe" value="1">pepe<br>
<input type="text" name="d"><br>
<input type="checkbox" name="pepe" value="1">pepe<br>
<input type="checkbox" name="pepe" value="1">pepe<br>
<input type="text" name="d"><br>
<input type="checkbox" name="pepe" value="1">pepe<br>
<input type="checkbox" name="pepe" value="1">pepe<br>
<input type="checkbox" name="pepe" value="1">pepe<br>
<input type="checkbox" name="pepe" value="1">pepe<br>
<input type="checkbox" name="pepe" value="1">pepe<br>
<input type="text" name="d"><br>
<input type="button" value="Marcar todos" onclick="marcar(this)">
</form>