Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/03/2006, 14:10
Avatar de Chuty
Chuty
 
Fecha de Ingreso: noviembre-2002
Ubicación: el bar de la esquina
Mensajes: 609
Antigüedad: 21 años, 6 meses
Puntos: 2
Habilitar problema con Javascript

Buenas a todos,
tengo el siguiente problema.
Tengo tres grupos de checkbox, el cual el primer grupo se habilita y deshabilita por medio de un radio , el segundo grupo tene la funcion de invertir y seleccionar todos y el tercero no importa no tiene que hacer ninguna funcion. El tema es que el primer grupo que tiene la funcion de habilitar o deshabilitar me deshabilita a todos les checkbox de la pantalla y no al grupo de el.
Por ejemplo este es codigo:


Código PHP:
<SCRIPT LANGUAGE="JavaScript"
function 
seleccionar(grupoestado) {
// grupo es el id contenedor
// estado es true/false
for (var 0checks document.getElementById(grupo).getElementsByTagName("input"), total checks.lengthtotal++)
checks[i].checked estado;
}

function 
invierte(grupo) { 
for (var 
0checks document.getElementById(grupo).getElementsByTagName("input"), total checks.lengthtotal++) 
checks[i].checked = !checks[i].checked;
}
</script>

// aca habilito y deshabilito, al deshabilitar me limpia los checkbox 
// seleccionados del grupo que son los A1 A2 A3 A4
<SCRIPT LANGUAJE="JavaScript">
function habilitaDeshabilita(form) {
  ele=form.elements;
  for(i=0;i<ele.length;i++)
    if(ele[i].type=='checkbox')
      ele[i].disabled=form.R1[0].checked;
      for (i=0; i<form.length; i++) {
        with (form.elements[i]) {
    if(className!='fieldset')
       if ( type == 'checkbox' ) { checked = false }
      }
  }
}
</SCRIPT>

<FORM NAME=formulario>

<input type="radio" value="Manual" name="R1" onClick="habilitaDeshabilita(this.form)">Manual 
<input type="radio" value="Automatico" checked name="R1" onClick="habilitaDeshabilita(this.form)">Automatico 
<DIV>
<input type="checkbox" name="A1" value="ON"> 
<input type="checkbox" name="A2" value="ON"> 
<input type="checkbox" name="A3" value="ON"> 
<input type="checkbox" name="A4" value="ON"> 
</DIV>
<input type="button" name="Bot1" value=" Todos " onClick='seleccionar("grupo1", true)' style="font-size: 8 pt" title="Seleccionar Todos" style="position: relative;  width: 70">&nbsp;&nbsp; 
<input type="button" name="Bot2" value="Invertir" onclick="invierte('grupo1')" style="font-size: 8 pt" title="Invertir Selección" style="position: relative;  width: 70">&nbsp;&nbsp; 
</td>
<div style=" OVERFLOW: auto; BORDER-LEFT: buttonshadow 1px; WIDTH: 650px; COLOR: windowtext; BORDER-BOTTOM: buttonhighlight 1px; SCROLLBAR-BASE-COLOR: buttonface; POSITION: relative; HEIGHT: 155px; BACKGROUND-COLOR: window" >
<fieldset id="grupo1">
<input type="checkbox" name="B1" value="ON"> 
<input type="checkbox" name="B2" value="ON"> 
<input type="checkbox" name="B3" value="ON"> 
<input type="checkbox" name="B4" value="ON"> 
</fieldset >
</div>
<DIV>
<input type="checkbox" name="C1" value="ON"> 
<input type="checkbox" name="C2" value="ON"> 
<input type="checkbox" name="C3" value="ON"> 
<input type="checkbox" name="C4" value="ON"> 
</DIV>
</FORM> 
desde ya muchas gracias y saludos a todos