
20/07/2011, 00:42
|
 | | | Fecha de Ingreso: octubre-2008 Ubicación: Madrid
Mensajes: 495
Antigüedad: 16 años, 3 meses Puntos: 66 | |
Respuesta: validar checkbox diferentes toma profe ;)
--------------------------------------
<html xmlns="http://www.w3.org/1999/xhtml" >
<head >
<title>Untitled Page</title>
<script type="text/javascript">
function validarFormulario()
{
//con un bucle recorremos todos los checkbox del formulario
//en el momento que uno esté marcado devolveremos un valor TRUE para que el formulario navegue
//a la página en cuestión
var checks = document.getElementsByTagName('input');
for(i=0;i<checks.length;i++)
{
if(checks[i].type=='checkbox')
{
if(checks[i].checked)
return true;
}
}
//si llegamos a este punto es que no había ningún checkbox marcado, así que mostramos
//una alerta y devolvemos FALSE, para que el formulario no navegue
alert('no has marcado ningún checkbox');
return false;
}
</script>
</head>
<body>
<form id="form1" method="post" action="http://www.google.com" onsubmit="return validarFormulario()" >
<div>
<input type="checkbox" />valor 1<br />
<input type="checkbox" />valor 2<br />
<input type="checkbox" />valor 3<br />
<input type="checkbox" />valor 4<br />
<input type="checkbox" />valor 5
</div>
<input type="submit" value="ir" />
</form>
</body>
</html>
--------------------------------------
esto es un ejemplo, tendrás que modificarlo a tu gusto.
saludos. |