Foros del Web » Programando para Internet » Javascript »

Como activar un boton si hay un checkbox seleccionado

Estas en el tema de Como activar un boton si hay un checkbox seleccionado en el foro de Javascript en Foros del Web. tengo el siguiente codigo: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código HTML: Ver original <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> < html xmlns = "http://www.w3.org/1999/xhtml" > < ...
  #1 (permalink)  
Antiguo 28/12/2010, 07:07
Avatar de xalupeao  
Fecha de Ingreso: mayo-2008
Ubicación: Santiago, Chile
Mensajes: 749
Antigüedad: 16 años
Puntos: 12
Como activar un boton si hay un checkbox seleccionado

tengo el siguiente codigo:

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=utf-8" />
  4. <title>Documento sin título</title>
  5. </head>
  6.  
  7. <form id="form1" name="form1" method="get" action="">
  8.   <input name="campos[]" type="checkbox" id="checkbox" value="1" onchange="enviar();"/>
  9.   <label for="checkbox"></label>
  10.   campo 1<br />
  11.   <input name="campos[]" type="checkbox" id="checkbox2" value="2" />
  12.   <label for="checkbox2"></label>
  13.   campo 2<br />
  14.   <input name="campos[]" type="checkbox" id="checkbox3" value="3" />
  15.   <label for="checkbox3"></label>
  16.   campo 3<br />
  17.   <input name="campos[]" type="checkbox" id="checkbox4" value="4" />
  18.   <label for="checkbox4"></label>
  19.   campo 4
  20.   <br />
  21.   <input type="submit" name="button" id="button" disabled value="Enviar" />
  22. </form>
  23. </body>
  24. </html>


lo que necesito es hablitar el boton "button" cuando cualquiera de los checkbox sea marcado.

no son solo 4 checkbox pueden ser x checkbox.

espero que me puedan ayudar, muchas gracias :)
__________________
Hosting en Chile en Silverhost - La solución en Hosting en Chile.
  #2 (permalink)  
Antiguo 28/12/2010, 07:14
 
Fecha de Ingreso: junio-2008
Ubicación: Capital Federal xD
Mensajes: 1.208
Antigüedad: 15 años, 10 meses
Puntos: 35
Respuesta: Como activar un boton si hay un checkbox seleccionado

La propiedad disabled del elemento del formulario te permite habilitar/deshabilitarlo.
document.form1.boton1.disabled=false;
__________________
I am Doyle please insert code.
  #3 (permalink)  
Antiguo 28/12/2010, 07:16
Avatar de xalupeao  
Fecha de Ingreso: mayo-2008
Ubicación: Santiago, Chile
Mensajes: 749
Antigüedad: 16 años
Puntos: 12
Respuesta: Como activar un boton si hay un checkbox seleccionado

entiendo, lo que quiero hacer es la condicion de que si cualquiera de los checkbox es marcado que se active, se activarlo, pero como plantear la condicion no.

gracias por tu pronta respuesta.
__________________
Hosting en Chile en Silverhost - La solución en Hosting en Chile.
  #4 (permalink)  
Antiguo 28/12/2010, 07:46
 
Fecha de Ingreso: junio-2008
Ubicación: Capital Federal xD
Mensajes: 1.208
Antigüedad: 15 años, 10 meses
Puntos: 35
Respuesta: Como activar un boton si hay un checkbox seleccionado

podrias bindearles a los checkbox a traves del evento Onclick una funcion.
Dicha función primero verifica que el checkbox esté tildado, si es así habilita el button.
__________________
I am Doyle please insert code.
  #5 (permalink)  
Antiguo 28/12/2010, 08:05
Avatar de xalupeao  
Fecha de Ingreso: mayo-2008
Ubicación: Santiago, Chile
Mensajes: 749
Antigüedad: 16 años
Puntos: 12
Respuesta: Como activar un boton si hay un checkbox seleccionado

realemente seria en un onChange pero la condicion es la que me complica.

ya que como determino si hay otro seleccionado.

entiendes?
__________________
Hosting en Chile en Silverhost - La solución en Hosting en Chile.
  #6 (permalink)  
Antiguo 28/12/2010, 08:10
 
Fecha de Ingreso: junio-2008
Ubicación: Capital Federal xD
Mensajes: 1.208
Antigüedad: 15 años, 10 meses
Puntos: 35
Respuesta: Como activar un boton si hay un checkbox seleccionado

El evento onchange solo aplica a select, text o textarea.
Te recomiendo onclick. Debes aplicarlo a todos los checkbox, al hacer click en alguno llama a dicha función.
__________________
I am Doyle please insert code.
  #7 (permalink)  
Antiguo 28/12/2010, 08:22
Avatar de xalupeao  
Fecha de Ingreso: mayo-2008
Ubicación: Santiago, Chile
Mensajes: 749
Antigüedad: 16 años
Puntos: 12
Respuesta: Como activar un boton si hay un checkbox seleccionado

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=utf-8" />
  4. <title>Documento sin título</title>
  5. <script type="text/javascript">
  6. function enviar(){
  7.     document.form1.button.disabled = true;
  8.     for (i=0;i<document.form1.elements.length;i++){
  9.         if(document.form1.elements[i].type == "checkbox"){
  10.             if(document.form1.elements[i].checked == 1 ){
  11.                 document.form1.button.disabled = false;
  12.                 i=document.form1.elements.length+10;
  13.             }
  14.         }
  15.     }
  16. }
  17. </head>
  18.  
  19. <form id="form1" name="form1" method="get" action="">
  20.   <input name="campos[]" type="checkbox" id="checkbox" value="1" onchange="enviar();" />
  21.   campo 1<br />
  22.   <input name="campos[]" type="checkbox" id="checkbox2" value="2" onchange="enviar();" />
  23.   campo 2<br />
  24.   <input name="campos[]" type="checkbox" id="checkbox3" value="3" onchange="enviar();" />
  25.   campo 3<br />
  26.   <input name="campos[]" type="checkbox" id="checkbox4" value="4" onchange="enviar();" />
  27.   campo 4
  28.   <br />
  29.   <input type="submit" name="button" disabled="disabled" id="button" value="Enviar" />
  30. </form>
  31. </body>
  32. </html>


Listo :)
__________________
Hosting en Chile en Silverhost - La solución en Hosting en Chile.

Etiquetas: checkbox, seleccionado, botones
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 22:42.