Ver Mensaje Individual
  #8 (permalink)  
Antiguo 05/09/2012, 17:23
Avatar de Briss
Briss
 
Fecha de Ingreso: junio-2011
Mensajes: 1.293
Antigüedad: 12 años, 10 meses
Puntos: 12
Respuesta: Adecuar mi funcion

Cita:
Iniciado por Dradi7 Ver Mensaje
Revisa este código que acabo de hacer y me dices si funciona a tu perfección

Supongamos que tu tienes estos checkbox

Código HTML:
Ver original
  1. <form name="frm" onsubmit="return false;">
  2. <input type="text" name="p1[]" id="p1" size="3"/><br/><br/>
  3. <input type="text" name="p1[]" id="p2" size="3"/><br/><br/>
  4. <input type="text" name="p1[]" id="p3" size="3"/><br/><br/>
  5. <input type="text" name="p1[]" id="p4" size="3"/><br/><br/>
  6. <input type="text" name="p1[]" id="p5" size="3"/><br/><br/>
  7. <input type="text" name="p1[]" id="p6" size="3"/><br/><br/>
  8. Cambia <input type="checkbox" name="porcentaje" id="porcentaje" value="0"/><br/><br/>
  9. </form>

y este seria el JavaScript

Código Javascript:
Ver original
  1. window.onload = function(){
  2.     var cambia = document.getElementById("porcentaje");
  3.     if(window.attachEvent)
  4.         cambia.attachEvent("onclick",Cambia);
  5.     else
  6.         cambia.addEventListener("click",Cambia);
  7.     Cambia();
  8. };
  9.  
  10. function Cambia(){
  11.     var c = this;
  12.     for (var i = 0; ele = document.getElementsByName("p1[]")[i]; i++){
  13.         ele.disabled = !c.checked;
  14.         console.log(i + " = " + ele.disabled);
  15.     }
  16. }

Acá puedes ver el demo funcionando

http://jsfiddle.net/ldiego/nNSDP/
Gracias por tu enorme paciencia he probado tu código en un nuevo documento html y funciona perfecto... pero al implementarlo en mi php no funciona
lo tengo asi
Código HTML:
<script type="text/javascript">
window.onload = function(){
    var cambia = document.getElementById("porcentaje");
    if(window.attachEvent)
        cambia.attachEvent("onclick",Cambia);
    else
        cambia.addEventListener("click",Cambia);
    Cambia();
};

function Cambia(){
    var c = this;
    for (var i = 0; ele = document.getElementsByName("p1[]")[i]; i++){
        ele.disabled = !c.checked;
        console.log(i + " = " + ele.disabled);
    }
}
</script> 

Código HTML:
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" onsubmit="return false;" id="form1"  >
 /> 
  <table border="0" class="normal">  
<td> <input type="checkbox" name="porcentaje" id="porcentaje" value="0"/></td>
  <thead>
    <tr>
      
      <td>Parcial 1</td>
 
 
 </tr>
    </tr>
  </thead>
  <?php do { ?>
  <tbody>

  
    <td><?php  $i+=1; echo $i;?></td>
    
      
  </tbody>
     <?php } while ($row_calificar = mysql_fetch_assoc($calificar)); ?>
</table>

    <p>
      <input type="button" value="Cancelar"  onClick="history.back()"/>
      <input type="submit" value="Evaluar" />
 
      <input type="hidden" name="MM_update" value="form1" />
    
</p>
</form> 

Crei que no omiti nada... salen los inputs inactivos y aunque presione el checkbox no se activan