Ver Mensaje Individual
  #2 (permalink)  
Antiguo 11/05/2010, 12:42
Avatar de _cronos
_cronos
 
Fecha de Ingreso: abril-2010
Mensajes: 135
Antigüedad: 14 años, 2 meses
Puntos: 1
Respuesta: Cambiar valor de checkbox si esta marcado

Por ejemplo:

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  4. <title>Documento sin t&iacute;tulo</title>
  5. </head>
  6.  
  7. <form action="" method="post" id='f1'>
  8. <input type='checkbox' id="check1" onclick='calcular()'/>Cambia value<br />
  9. Value del checkbox:<input type="text" id="text1" />
  10. </form>
  11. </body>
  12. </html>

Código Javascript:
Ver original
  1. <script type="text/javascript">
  2. function calcular(){
  3.  if (document.getElementById('check1').checked==true){
  4.   document.getElementById('check1').value=10;
  5.   document.getElementById('text1').value=document.getElementById('check1').value;
  6.   }else{
  7.   document.getElementById('check1').value=20;
  8.   document.getElementById('text1').value=document.getElementById('check1').value;
  9.   }
  10.  }
  11. </script>

Espero que te sirva (: