Ver Mensaje Individual
  #2 (permalink)  
Antiguo 05/12/2007, 18:53
Avatar de Panino5001
Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años, 9 meses
Puntos: 834
Re: hacer checkbox dinamico y el script tambien dinamico ?

Fijate si esto te sirve:
Código PHP:
<html>

<
head>

<
title>Loto Test</title>

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

<
style type=text/css>

body {color:blue;background-color:green;}

.
ts {color:hotpink;background-color:white;}

</
style>

<
script>
function 
pintar(e){
e=|| window.event;
oe.srcElement || e.target;
colores=['pink','white'];
color=o.checked?colores[0]:colores[1];
au=document.getElementsByTagName('input');
for(
i=0,j=0;i<au.length;i++){
if(
au[i].type!='checkbox')continue;
if(
au[i].checked==true)j++;
if(
j>3){
alert('no más de 3');
o.checked=false;
return;
}
}
o.parentNode.style.backgroundColor=color;
}
function 
evaluar(obj){
obj.onclick=function(event){
pintar(event);
}
}
window.onload=function(){
au=document.getElementsByTagName('input');
for(
i=0;i<au.length;i++){
if(
au[i].type!='checkbox')continue;
evaluar(au[i])
}
}
</script>

</head>

<body style="color: #000000; background-color: #FFFFFF">






Por favor, seleccione 3 opciones como m&aacute;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" value="ON">
  <td class=ts id=t2>02
    <input type=checkbox name="c2"  value="ON">
  <td class=ts id=t3>03
    <input type=checkbox name="c3"  value="ON">
  <td class=ts id=t4>04
    <input type=checkbox name="c4"  value="ON">
  <td class=ts id=t5>05
    <input type=checkbox name="c5"  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> 

Última edición por Panino5001; 06/12/2007 a las 14:50