Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/12/2007, 11:23
anibal_cdf
 
Fecha de Ingreso: marzo-2007
Mensajes: 180
Antigüedad: 17 años, 2 meses
Puntos: 0
limitar cantidad de checkbox a tildar ?

buenas que tal, tengo este script el cual quisiera si me pueden ayudar a que al marcarlo (ademas de pintarlo de color) me valide una cantidad maxima de items a tildar

por ejemplo si yo pongo maximo 3, que cuando quiera tildar el 4to no me lo tilde y ademas tampoco me cambie el color del fondo

este es el codigo q tengo ahora

Código:
<html>
<head>
<title>Cambia celda de color al seleccionar checkbox</title>
<!--
This file retrieved from the JS-Examples archives
http://www.js-examples.com
100s of free ready to use scripts, tutorials, forums.
Author: JS-Examples - http://www.js-examples.com/ 
-->
<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>
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 doIt(_v)
{
  var X=eval("document.exf1.c"+_v+".checked?0:1");
  if(isIE)
  {
    eval("t"+_v+".style.backgroundColor=bC[X]");
    eval("t"+_v+".style.color=C[X]");
  }
  if(isNS6)
  {
    document.getElementById("t"+_v).style.backgroundColor=bC[X];
    document.getElementById("t"+_v).style.color=C[X];
  }
}
</script>
</b></p>
<form name=exf1>
<table border=1 cellpadding=3 cellspacing=3 align=center>
<tr><td class=ts id=t1>01<input type=checkbox name=c1 onclick=doIt(1) value="ON"></tr>
<tr><td class=ts id=t2>02<input type=checkbox name=c2 onclick=doIt(2) value="ON"></tr>
<tr><td class=ts id=t3>03<input type=checkbox name=c3 onclick=doIt(3) value="ON"></tr>
<tr><td class=ts id=t4>04<input type=checkbox name=c4 onclick=doIt(4) value="ON"></tr>
<tr><td class=ts id=t5>05<input type=checkbox name=c5 onclick=doIt(5) value="ON"></tr>
</table>
</form>
</body>
</html>