Foros del Web » Programando para Internet » Javascript »

Validar diferentes checkbox en un formulario

Estas en el tema de Validar diferentes checkbox en un formulario en el foro de Javascript en Foros del Web. Hola: Mi prolema es el que tengo un formulario con varios campos para escoger en chekbox como son color,uso,material, en donde cada uno de estos ...
  #1 (permalink)  
Antiguo 08/09/2006, 09:46
 
Fecha de Ingreso: agosto-2006
Mensajes: 10
Antigüedad: 17 años, 8 meses
Puntos: 0
Validar diferentes checkbox en un formulario

Hola:

Mi prolema es el que tengo un formulario con varios campos para escoger en chekbox como son color,uso,material, en donde cada uno de estos tiene varios checkbox para escoger, lo que quiero es que valide para que por lo menos elija una opcion es decir un color,un uso y un material.
  #2 (permalink)  
Antiguo 08/09/2006, 09:55
Avatar de rock_blues.NET  
Fecha de Ingreso: septiembre-2005
Mensajes: 207
Antigüedad: 18 años, 8 meses
Puntos: 0
y como realizar la validacion al presionar un boton.. o algo asi..??
muestra un poco de codigo
  #3 (permalink)  
Antiguo 08/09/2006, 10:13
Avatar de rock_blues.NET  
Fecha de Ingreso: septiembre-2005
Mensajes: 207
Antigüedad: 18 años, 8 meses
Puntos: 0
si es con un botoncillo este es el codigo

Código HTML:
<head> <script language="JavaScript">  
	function valores()
	{
	var sw=0;
		for(c=1; c<=4; c++)
			{
				if (document.forms['formulario']['box'+c].checked==true)
				{
					sw=1;
					break;		
				}
			}
			if (sw==1)
			{
				var msje='';
				for(c=1; c<=4; c++)
				{
					if (document.forms['formulario']['box'+c].checked==true)
					msje=msje+" "+document.forms['formulario']['box'+c].value+",";
				}
				alert("Escogio :"+msje);

			}else
			{
				alert("no ha selecccionado nada");
			}
	}
</script> 
</head> 
<body> 
<form name="formulario" action="nuevo.html" method="get"> 

<input type="checkbox" value="rojo" name="box1">rojo
<BR>
<input type="checkbox" value="azul" name="box2">azul
<BR>
<input type="checkbox" value="blanco" name="box3">blanco
<BR>
<input type="checkbox" value="verde" name="box4">verde
<BR>
<input type="button"value="pasa o no?" onClick="valores()">
</form>
</body> 
avisame si te sirve
  #4 (permalink)  
Antiguo 08/09/2006, 10:17
 
Fecha de Ingreso: agosto-2006
Mensajes: 10
Antigüedad: 17 años, 8 meses
Puntos: 0
este es parte del codigo:

<th scope="col"><div align="right">Color :</div></th>
<th scope="col">&nbsp;</th>
<th height="45" scope="col"><br />
<label>
<table width="227" border="0" align="left" cellpadding="0" cellspacing="0">
<? while ($row4=mysql_fetch_array($result)) { ?>
<tr>
<td width="27" bgcolor="<? echo $row4['hexadecimal'] ?>">&nbsp;</td>
<td width="43"><div align="center">
<input type="checkbox" name="color[]"value="<? echo $row4['id_color'] ?>" />
</div></td>
<td width="157" height="22"><? echo $row4['color'] ?></td>

</tr>
<? } ?>
<a href="javascript:abrir('color.php?id=<? $row ['id_producto'] ?>')">Otros Colores </a>
</table>
<p align="left">&nbsp;</p>
</label></th>
</tr>
<tr>
<th scope="col"><div align="right">Uso :</div></th>
<th scope="col">&nbsp;</th>
<th height="38" scope="col"><table width="362" height="109" border="0" align="left" cellpadding="0" cellspacing="0">

<tr>
<td height="22"><input type="checkbox" name="uso[]" value="Hogar">
Hogar</td>
<td><input type="checkbox" name="uso[]" value="Oficina">
Oficina</td>
<td><input type="checkbox" name="uso[]" value="Auditorio">
Auditorio</td>
</tr>
<tr>
<td height="23"><label>
<input type="checkbox" name="uso[]" value="Hospital">
Hospital</label></td>
<td><label>
<input type="checkbox" name="uso[]" value="Hoteles">
Hoteles</label></td>
<td><label>
<input type="checkbox" name="uso[]" value="Diseño Especial">
Dise&ntilde;o Especial </label></td>
</tr>
<tr>
<td height="23"><input type="checkbox" name="uso[]" value="Jardin">
Jardin
</label></td>
<td><input type="checkbox" name="uso[]" value="Escolar">
Escolar
<label></label></td>
<td><input type="checkbox" name="uso[]" value="Restaurant/Bar">
Restaurant/Bar
<label></label></td>
</tr>
<tr>
<td width="89" height="39"><label>
<input type="checkbox" name="uso[]" value="Tienda de Autoservicio">
Tienda de Autoservicio </label></td>
<td width="106"><label>
<input type="checkbox" name="uso[]" value="Salon de Fiestas">
Salon de Fiestas </label></td>
<td width="100">&nbsp;</td>
</tr>
</table></th>
</tr>
<tr>
<th scope="col"><div align="right">Estilo :</div></th>
<th scope="col">&nbsp;</th>
<th height="38" scope="col"><table width="367" height="78" border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td height="39"><label>
<input type="checkbox" name="estilo[]" value="Rustico" />
</label>
R&uacute;stico
</td>
<td><input type="checkbox" name="estilo[]" value="Minimalista" />
Minimalista
</td>
<td><input type="checkbox" name="estilo[]" value="Contemporanea" />
Contempor&aacute;neo</td>
</tr>
<tr>
<td width="109" height="39"><label>
</label>
<label>
<input type="checkbox" name="estilo[]" value="Colonial" />
Colonial</label></td>
<td width="130"><label>
</label>
<label>
<input type="checkbox" name="estilo[]" value="Modernista" />
Modernista</label></td>
<td width="128"><label>
</label>
<label></label></td>
</tr>
</table></th>
</tr>

<tr>
<th scope="col"><div align="right">Material :</div></th>
<th scope="col">&nbsp;</th>
<th height="38" scope="col"><div align="left">
<table width="369" height="117" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="39"><input type="checkbox" name="material[]" value="Herreria" />
Herrer&iacute;a
</td>
<td><input type="checkbox" name="material[]" value="Madera" />
Madera
</td>
<td><input type="checkbox" name="material[]" value="Granito/Cuarzo" />
Granito/Cuarzo</td>
</tr>
<tr>
<td height="39"><label>
<input type="checkbox" name="material[]" value="MDF" />
MDF</label></td>
<td><label>
  #5 (permalink)  
Antiguo 08/09/2006, 10:19
Avatar de rock_blues.NET  
Fecha de Ingreso: septiembre-2005
Mensajes: 207
Antigüedad: 18 años, 8 meses
Puntos: 0
revisa el codigo q te envie.. es expandible para todo tu 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

SíEste tema le ha gustado a 1 personas (incluyéndote)




La zona horaria es GMT -6. Ahora son las 19:16.