Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/12/2007, 18:16
anibal_cdf
 
Fecha de Ingreso: marzo-2007
Mensajes: 180
Antigüedad: 18 años
Puntos: 0
hacer checkbox dinamico y el script tambien dinamico ?

tengo este scritp de prueba con 5 checks, pero lo tengo q hacer con 38 ... la idea seria que donde dice a= casilla.form ..... sea en realidad dinamico para no usar 38 variables
y despues en el contador tampoco usar 38 comparaciones ...

alguna idea ?

Código:
<html>

<head>

<title>Loto Test</title>

<p align="center"><b>Cambia celda de color al seleccionar checkbox, y limita a 3 las selecciones</b></p>

<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,casilla,form)

{

 

            a = casilla.form.c1.checked;

            b = casilla.form.c2.checked;

            c = casilla.form.c3.checked;

            d = casilla.form.c4.checked;

            e = casilla.form.c5.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;

    }

 

  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>



Por favor, seleccione 3 opciones como máximo:<br>

<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,this,this.form) value="ON">
  <td class=ts id=t2>02
    <input type=checkbox name="c2" onclick=doIt(2,this,this.form) value="ON">
  <td class=ts id=t3>03
    <input type=checkbox name="c3" onclick=doIt(3,this,this.form) value="ON">
  <td class=ts id=t4>04
    <input type=checkbox name="c4" onclick=doIt(4,this,this.form) value="ON">
  <td class=ts id=t5>05
    <input type=checkbox name="c5" onclick=doIt(5,this,this.form) value="ON">
  <td class=ts id=t1>  
  <td class=ts id=t1></tr>

<tr>
  <td class=ts id=t2>
  
  <td class=ts id=t2>
  
  <td class=ts id=t2>  
  <td class=ts id=t2>  
  <td class=ts id=t2>  
  <td class=ts id=t2>  
  <td class=ts id=t2></tr>

<tr>
  <td class=ts id=t3>
  
  <td class=ts id=t3>
  
  <td class=ts id=t3>  
  <td class=ts id=t3>  
  <td class=ts id=t3>  
  <td class=ts id=t3>  
  <td class=ts id=t3></tr>

<tr>
  <td class=ts id=t4>
  
  <td class=ts id=t4>
  
  <td class=ts id=t4>  
  <td class=ts id=t4>  
  <td class=ts id=t4>  
  <td class=ts id=t4>  
  <td class=ts id=t4></tr>

<tr>
  <td class=ts id=t5>
  
  <td class=ts id=t5>
  
  <td class=ts id=t5>  
  <td class=ts id=t5>  
  <td class=ts id=t5>  
  <td class=ts id=t5>  
  <td class=ts id=t5></tr>
<tr>
  <td class=ts id=t6>
  <td class=ts id=t6>
  <td class=ts id=t6>
  <td class=ts id=t6>
  <td class=ts id=t6>
  <td class=ts id=t6>
  <td class=ts id=t6></tr>
<tr>
  <td class=ts id=t7>
  <td class=ts id=t7>
  <td class=ts id=t7>
  <td class=ts id=t7>
  <td class=ts id=t7>
  <td class=ts id=t7>
  <td class=ts id=t7></tr>
</table>

</form>

 

 

</body>

 

</html>