Foros del Web » Creando para Internet » HTML »

casillas de verificacion

Estas en el tema de casillas de verificacion en el foro de HTML en Foros del Web. Hola muy buenas a todos, mi caso esque tengo varias casillas de verificacion; y me gustaria que cuando seleciono una en particular todas las demas ...
  #1 (permalink)  
Antiguo 14/08/2007, 06:04
 
Fecha de Ingreso: marzo-2007
Mensajes: 31
Antigüedad: 17 años, 1 mes
Puntos: 0
casillas de verificacion

Hola muy buenas a todos,

mi caso esque tengo varias casillas de verificacion; y me gustaria que cuando seleciono una en particular todas las demas se me selecionen. Vamos que tienes varias opciones y una de ellas es seleccionar todas ellas.

Se podria hacer???. Muchas gracias por la ayuda,

Juanstan
  #2 (permalink)  
Antiguo 14/08/2007, 06:57
 
Fecha de Ingreso: enero-2007
Mensajes: 272
Antigüedad: 17 años, 3 meses
Puntos: 5
Re: casillas de verificacion

Hola:

Esto lo puedes hacer mediante javascript, te dejo una función que hice para este próposito:

Código PHP:
function checkall() {
   
   
i=1;
    
   var 
arraycheck document.form1["borrar[]"];
        
totalcontroles=arraycheck.length;
        if (
totalcontroles 0
        if (
arraycheck[0].checked==true)
          
            while (
i<totalcontroles){
               if (
arraycheck[i].disabled == false)
                 
arraycheck[i].checked=true;
               else 
                      
arraycheck[i].checked=false;              
                 
i=i+1;
            } 
        else
              while (
i<totalcontroles){
               
                  
arraycheck[i].checked=false;
                  
i=i+1
              }  

Tus checkbox lo puedes llamar de la siguiente forma:

Código:
<input name="borrar[1]" id="borrar[]" type="checkbox">
<input name="borrar[2]" id="borrar[]" type="checkbox">
<input name="borrar[3]" id="borrar[]" type="checkbox">
Hasta Luego .-
  #3 (permalink)  
Antiguo 14/08/2007, 09:33
 
Fecha de Ingreso: marzo-2007
Mensajes: 31
Antigüedad: 17 años, 1 mes
Puntos: 0
Re: casillas de verificacion

Muchas gracias por tu respuesta,

Una pregunta, que deberia poner en la cabezera del formulario para llamar a la funcion javascript????

Yo he puesto esto

Código HTML:
function checkall() {
   i=1;
   var arraycheck = document.form1["borrar[]"];
        totalcontroles=arraycheck.length;
        if (totalcontroles > 0) 
        if (arraycheck[0].checked==true)
          
            while (i<totalcontroles){
               if (arraycheck[i].disabled == false)
                 arraycheck[i].checked=true;
               else 
                      arraycheck[i].checked=false;              
                 i=i+1;
            } 
        else
              while (i<totalcontroles){
               
                  arraycheck[i].checked=false;
                  i=i+1; 
              }   
	}
//-->
</script> 
y esto en el form:
Código PHP:
<?php
    
    $page_content 
= <<<PAGEOUT
<form id="form1" name="form1" method="post" action="" onsubmit="checkall()">
  <table align="center" cellspacing="0" cellpadding="0" border="2">
      <tr>
        <td id="headerTable" colspan="3"><p class="headerForm">Find the nearest CFA Approved Distributor to:</p>
        <p class="headerForm2">POSTCODE <input type="text" name="postcode" size="6" />
        OR TOWN <input type="text" name="town" /></p>
        (Please enter first digits only e.g. LE15 or SW1)</td>
    </tr>
    <tr><td class="bodyForm">I am looking for fixings from</td><td align="center"><strong>ANY MEMBER</strong></td><td><input name="borrar[0]" id="borrar[]" type="checkbox"/></td></tr>
    <tr><td rowspan="5" valign="top" class="bodyForm">or from</td><td align="center"><img src="supplier1.png" height="25px" width="100px"/></td><td><input name="borrar[1]" id="borrar[]" type="checkbox" /></td></tr>
    <tr><td align="center"><img src="supplier2.png" height="25px" width="100px"/></td><td><input name="borrar[2]" id="borrar[]" type="checkbox"/></td></tr>
    <tr><td align="center"><img src="supplier3.png" height="25px" width="100px"/></td><td><input name="borrar[3]" id="borrar[]" type="checkbox" /></td></tr>
    <tr><td align="center"><img src="supplier4.png" height="25px" width="100px"/></td><td><input name="borrar[4]" id="borrar[]" type="checkbox"/></td></tr>
    <tr><td align="center"><img src="supplier5.png" height="25px" width="100px"/></td><td><input name="borrar[5]" id="borrar[]" type="checkbox"/></td></tr>
    <tr><td colspan="3" align="center"><input type="submit" name="Submit" value="Enviar" class="botonReg" /></td>
</table>
</form>
PAGEOUT;
?>
pero no me funciona, seguramente este haciendo algo mal,
me lo puedes decir?????,

Gracias de nuevo

Última edición por juanstan; 14/08/2007 a las 09:39
  #4 (permalink)  
Antiguo 14/08/2007, 13:12
 
Fecha de Ingreso: enero-2007
Mensajes: 272
Antigüedad: 17 años, 3 meses
Puntos: 5
Re: casillas de verificacion

Hola:

Le he hecho una pequeña modificación, te dejo el ejemplo completo.

Código:
<?xml version="1.0" encoding="windows-1252"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title></title>
</head>
<body>
<form name="form1" action="" method="post">
   <input name="borrar[1]" id="borrar[]" type="checkbox">
   <input name="borrar[2]" id="borrar[]" type="checkbox">
   <input name="borrar[3]" id="borrar[]" type="checkbox">
   <input type="button" value="Check" onclick="checkall();"/>
</form>

</body>


<script>
function checkall() {
   
   i=0;
    
   var arraycheck = document.form1["borrar[]"];
   totalcontroles=arraycheck.length;
   
   if (totalcontroles > 0) 
   //if (arraycheck[0].checked==true)
          
      while (i<totalcontroles){
         if (arraycheck[i].disabled == false)
            arraycheck[i].checked=true;
         else 
            arraycheck[i].checked=false;              
				 
            i=i+1;
     } 
   else
      while (i<totalcontroles){
         arraycheck[i].checked=false;
         i=i+1; 
      }  
}

</script>

</html>

Hasta Luego .-
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 15:33.