04/12/2007, 19:54
|
| | Fecha de Ingreso: marzo-2007
Mensajes: 180
Antigüedad: 17 años, 10 meses Puntos: 0 | |
Re: limitar cantidad de checkbox a tildar ? no me sale, pruebo esto y funciona q no me deje marcar mas de 3 pero no me pinta el fondo de color al seleccionarlo
Código:
<html>
<head>
<title>Cambia celda de color al seleccionar checkbox</title>
<p align="center"><b>Cambia celda de color al seleccionar checkbox
<style type=text/css>
body {color:blue;background-color:green;}
.ts {color:hotpink;background-color:white;}
</style>
</head>
<body style="color: #000000; background-color: #FFFFFF">
<script language="javascript">
isIE=document.all?true:false;
var isNS4=document.layers?true:false;
var isNS6=navigator.userAgent.indexOf("Gecko")!=-1?true:false;
var bC=new Array('pink','white');
var C=new Array('black','hotpink');
function limitarSelección(casilla,form)
{
a = casilla.form.casilla1[0].checked;
b = casilla.form.casilla1[1].checked;
c = casilla.form.casilla1[2].checked;
d = casilla.form.casilla1[3].checked;
e = casilla.form.casilla1[4].checked;
contador = (a ? 1 : 0) + (b ? 1 : 0) + (c ? 1 : 0) + (d ? 1 : 0) + (e ? 1 : 0);
if (contador > 3)
{
alert("Solo puedes seleccionar 3 opciones");
casilla.checked = false;
}
else
{
var X=eval("document.exf1.c"+_v+".checked?0:1");
if(isIE)
{
eval("t"+casilla+".style.backgroundColor=bC[X]");
eval("t"+casilla+".style.color=C[X]");
}
if(isNS6)
{
document.getElementById("t"+casilla).style.backgroundColor=bC[X];
document.getElementById("t"+casilla).style.color=C[X];
}
}
}
</script>
<form name="ejemplo11" method="GET" action="pagina.htm" target="_blank">
Por favor, seleccione 3 opciones como máximo:<br>
<input type="checkbox" name="casilla1" value="Opcion 1" onClick="limitarSelección(this,this.form)">Opción 1<br>
<input type="checkbox" name="casilla1" value="Opcion 2" onClick="limitarSelección(this,this.form)">Opción 2<br>
<input type="checkbox" name="casilla1" value="Opcion 3" onClick="limitarSelección(this,this.form)">Opción 3<br>
<input type="checkbox" name="casilla1" value="Opcion 4" onClick="limitarSelección(this,this.form)">Opción 4<br>
<input type="checkbox" name="casilla1" value="Opcion 5" onClick="limitarSelección(this,this.form)">Opción 5<br>
<input type="submit" value="Enviar">
</form>
</body>
</html>
|