Que tal amigos y amigas...
Este código funciona muy bien....peroooo...
cuando en el formulario hay otros campos, además de los checkboxes, entonces no anda bien...
Fijense en el código que incluye otros campos...
Se les ocurre alguna solución?
Saludos, Luis Vásquez
Código:
<html>
<head>
<script>
function todos(){
ch=document.forms['form1'].elements;
alert('el formulario tiene :'+ch.length+' campos. ¿como saber cuales son checkboxes?');
for(x=0;x<ch.length-1;x++)
ch[x].checked = ch[ch.length-1].checked;
}
function comprobar(c){
document.forms['form1']['checkbox'].checked=false;
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
<p><br>
</p>
<table width="723" border="1">
<tr>
<td><input type="checkbox" name="checkbox2" value="checkbox" onClick="comprobar(this)">
uno</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox3" value="checkbox"onClick="comprobar(this)">
dos</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label>
<input type="text" name="textfield" id="textfield">
</label></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox4" value="checkbox" onClick="comprobar(this)">
tres</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label>
<select name="select" id="select">
</select>
</label></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox" value="checkbox" onClick="todos()">
todos </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label>
<input type="submit" name="button" id="button" value="Enviar">
</label></td>
<td> </td>
<td> </td>
</tr>
</table>
<p><br>
<br>
</p>
<p> </p>
</form>
</body>
</html>