Foros del Web » Programando para Internet » Javascript »

Checkbox en formulario....

Estas en el tema de Checkbox en formulario.... en el foro de Javascript en Foros del Web. Hola, como puedo hacer que si hago click en 1 checkbox, me salga 1 textbox para escribir? y si lo deselecciono se quite? MUEVANLO A ...
  #1 (permalink)  
Antiguo 08/06/2010, 10:17
Avatar de Most  
Fecha de Ingreso: marzo-2009
Mensajes: 642
Antigüedad: 15 años, 1 mes
Puntos: 6
Checkbox en formulario....

Hola, como puedo hacer que si hago click en 1 checkbox, me salga 1 textbox para escribir? y si lo deselecciono se quite?


MUEVANLO A HTML QUE ME CONFUNDIDO DE CATEGORÍA
  #2 (permalink)  
Antiguo 08/06/2010, 10:25
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Tema movido desde PHP a Javascript
  #3 (permalink)  
Antiguo 08/06/2010, 10:38
Avatar de _cronos2
Colaborador
 
Fecha de Ingreso: junio-2010
Mensajes: 2.062
Antigüedad: 13 años, 10 meses
Puntos: 310
Respuesta: Checkbox en formulario....

Código Javascript:
Ver original
  1. function texto(a,b){
  2.  if(document.getElementById(a).checked==true){
  3.   document.getElementById(b).style.display = 'block';
  4.  }else{
  5.   document.getElementById(b).style.display = 'none';
  6.  }
  7. }

Código HTML:
Ver original
  1. <input type='checkbox' onclick='texto(this, "caja");' />
  2. <input type='text' id='caja' style='display:none;' />

Saludos (:
  #4 (permalink)  
Antiguo 08/06/2010, 10:53
Avatar de Most  
Fecha de Ingreso: marzo-2009
Mensajes: 642
Antigüedad: 15 años, 1 mes
Puntos: 6
Respuesta: Checkbox en formulario....

gracias por el code, lo he probado asi y no funciona:

1. he creado el archivo: casilla.js con el codigo Javascript
2. he añadido <?php include("casillas.js"); ?>
3. Y en <body> he añadido:

Código HTML:
<input type='checkbox' onclick='texto(this, "caja");' />
<input type='text' id='caja' style='display:none;' /> 

y no funciona
  #5 (permalink)  
Antiguo 08/06/2010, 11:04
Avatar de _cronos2
Colaborador
 
Fecha de Ingreso: junio-2010
Mensajes: 2.062
Antigüedad: 13 años, 10 meses
Puntos: 310
Respuesta: Checkbox en formulario....

Vale, perdón, esque lo escribí sin fijarme. Esto sí funciona poruqe lo comprobé.

Código Javascript:
Ver original
  1. <script type="text/javascript">
  2. function texto(a,b){
  3.  if(document.getElementById(a).checked==true){
  4.   document.getElementById(b).style.display = 'block';
  5.  }else{
  6.   document.getElementById(b).style.display = 'none';
  7.  }
  8. }
  9. </script>

Código HTML:
Ver original
  1. <input type='checkbox' id='chk' onclick='texto(this.id, "caja");' /><!--->Ni tenía id ni había puesto this.id -.-'<!--->
  2. <input type='text' id='caja' style='display:none;' />

Saludos y perdón (:
  #6 (permalink)  
Antiguo 08/06/2010, 11:08
Avatar de Most  
Fecha de Ingreso: marzo-2009
Mensajes: 642
Antigüedad: 15 años, 1 mes
Puntos: 6
Respuesta: Checkbox en formulario....

Muchas gracias amigo
  #7 (permalink)  
Antiguo 08/06/2010, 15:39
Avatar de Most  
Fecha de Ingreso: marzo-2009
Mensajes: 642
Antigüedad: 15 años, 1 mes
Puntos: 6
Respuesta: Checkbox en formulario....

cronos por que solo me deja poner 1 checkbox?, cuando pongo otro, no me sale el textarea al seleccionar :S ya que necesito miinimo 5....
  #8 (permalink)  
Antiguo 08/06/2010, 15:55
Avatar de _cronos2
Colaborador
 
Fecha de Ingreso: junio-2010
Mensajes: 2.062
Antigüedad: 13 años, 10 meses
Puntos: 310
Respuesta: Checkbox en formulario....

¿Necesitas 5 checkbox con cada text invisible? Entonces es igual.

Código HTML:
Ver original
  1. <input type='checkbox' id='chk' onclick='texto(this.id, "caja");' />
  2. <input type='text' id='caja' style='display:none;' /><br />
  3. <input type='checkbox' id='chk2' onclick='texto(this.id, "caja2");' />
  4. <input type='text' id='caja2' style='display:none;' /><br />
  5. <input type='checkbox' id='chk3' onclick='texto(this.id, "caja3");' />
  6. <input type='text' id='caja3' style='display:none;' /><br />
  7. <input type='checkbox' id='chk4' onclick='texto(this.id, "caja4");' />
  8. <input type='text' id='caja4' style='display:none;' /><br />
  9. <input type='checkbox' id='chk5' onclick='texto(this.id, "caja5");' />
  10. <input type='text' id='caja5' style='display:none;' /><br />

Saludos (:
  #9 (permalink)  
Antiguo 08/06/2010, 16:00
Avatar de Most  
Fecha de Ingreso: marzo-2009
Mensajes: 642
Antigüedad: 15 años, 1 mes
Puntos: 6
Respuesta: Checkbox en formulario....

Cita:
Iniciado por _cronos2 Ver Mensaje
¿Necesitas 5 checkbox con cada text invisible? Entonces es igual.

Código HTML:
Ver original
  1. <input type='checkbox' id='chk' onclick='texto(this.id, "caja");' />
  2. <input type='text' id='caja' style='display:none;' /><br />
  3. <input type='checkbox' id='chk2' onclick='texto(this.id, "caja2");' />
  4. <input type='text' id='caja2' style='display:none;' /><br />
  5. <input type='checkbox' id='chk3' onclick='texto(this.id, "caja3");' />
  6. <input type='text' id='caja3' style='display:none;' /><br />
  7. <input type='checkbox' id='chk4' onclick='texto(this.id, "caja4");' />
  8. <input type='text' id='caja4' style='display:none;' /><br />
  9. <input type='checkbox' id='chk5' onclick='texto(this.id, "caja5");' />
  10. <input type='text' id='caja5' style='display:none;' /><br />

Saludos (:

ahh muchas gracias, abia probado antes y no iba

Etiquetas: checkbox, formulario
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:10.