So I'm trying to use the following script:
//Limit of checked checkboxes
function checkboxlimit(checkgroup, limit){
var checkgroup=checkgroup
var limit=limit
for (var i=0; i<checkgroup.length; i++){
checkgroup[i].onclick=function(){
var checkedcount=0
for (var i=0; i<checkgroup.length; i++)
checkedcount+=(checkgroup[i].checked)? 1 : 0
if (checkedcount>limit){
alert("You can only select a maximum of "+limit+" checkboxes")
this.checked=false
}
}
}
}
//change bg color if checked
var seleccionado=new Array()
function cambia(fila){
if(seleccionado[fila]!=true)
{
document.getElementById("fila"+fila).style.background='#A5FA9B';
document.getElementById("fila"+fila).style.color='#FFFFFF';
seleccionado[fila]=true;
}
else
{
document.getElementById("fila"+fila).style.background='#FFF3D6';
document.getElementById("fila"+fila).style.color='#000000';
seleccionado[fila]=false;
}
}
So the first function will restrict the number of checkboxes you can select and the second will change the color of the cell background once checked. The HTML would be somthing like:
<form id="main" name="main" method="POST">
<font face="verdana">
<table>
<tr >
<td id="fila1">FIRST<input name="ckb" onclick="cambia(1)" type="checkbox"/></td>
<td id="fila2">SECOND<input name="ckb" onclick="cambia(2)" type="checkbox"/></td>
<td id="fila3">THIRD<input name="ckb" onclick="cambia(3)" type="checkbox"/></td>
</table>
</font>
</form>
And at the end a have to add the next script:
<script type="text/javascript">
checkboxlimit(document.forms.main.ckb, 1);
</script>
Now, they both work perfectly alone but when I combine them only the one that restricts the number of checked boxes works. Is there a way to make them work together?