Ver Mensaje Individual
  #30 (permalink)  
Antiguo 03/02/2012, 11:17
Avatar de goteen_mx
goteen_mx
 
Fecha de Ingreso: abril-2005
Ubicación: D.F.
Mensajes: 403
Antigüedad: 19 años, 11 meses
Puntos: 37
Respuesta: cambiar valores de checkbox

Código Javascript:
Ver original
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function calcular(obj, opc){
  5.     if(opc==1)
  6.         obj.checked = (document.getElementById("chk_todos").checked==true)?true:false;
  7.     var val = (obj.checked == true)? obj.id.split("_")[1] : 0;
  8.     obj.value = val;
  9.     document.getElementById("text_"+ obj.id.split("_")[1]).value = val;
  10. }
  11.  
  12. function calcularTodos(){
  13.     for(var i = 0 ; i < document.getElementsByName("chk").length; i++)
  14.         calcular(document.getElementsByName("chk")[i], 1);
  15. }
  16.  
  17. </script>
  18. </head>
  19. <body>
  20. <form>
  21. <input name='chk' type='checkbox' id="check_1" onclick="calcular(this,0);" />
  22. Cambia value
  23. Value del checkbox:
  24. <input type="text" id="text_1" />
  25.  
  26. <input name='chk' type='checkbox' id="check_2" onclick="calcular(this,0);" />
  27. Cambia value
  28. Value del checkbox:
  29. <input type="text" id="text_2" />
  30. <br>
  31. Todos:
  32. <input type='checkbox' id='chk_todos' onclick="calcularTodos();" />
  33. </form>
  34. </body>
  35. </html>
__________________
Born to be free.

Última edición por goteen_mx; 03/02/2012 a las 11:22