Puoi fare cosi ( testato su IE )
codice:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
var maxChecked = 4;
function controlla(checkbox,radice, numMass) {
if (numMass == null) {
numMass = maxChecked;
} // if (numMass == null)
oColl = document.getElementsByTagName('INPUT');
len = oColl.length;
checkedIn = 0;
for (i=0;i<len;i++) {
curObj = oColl.item(i);
if (curObj.type == 'checkbox' && curObj.id.substr(0,radice.length) == radice) {
if (curObj.checked == true) {
checkedIn ++;
} // if (curObj.checked == true)
} // if (curObj.type == 'checkbox' && curObj.id.substr(0,radice.length) == radice)
} // for (i=0;i<len;i++)
if (checkedIn > numMass) {
checkbox.checked = false;
return false;
}
return true;
} //
//-->
</script>
</head>
<body>
Selezionare 2
<input type="checkbox" id="cb1" onclick="controlla(this,'cb',2)">
<input type="checkbox" id="cb2" onclick="controlla(this,'cb',2)">
<input type="checkbox" id="cb3" onclick="controlla(this,'cb',2)">
<input type="checkbox" id="cb4" onclick="controlla(this,'cb',2)">
<input type="checkbox" id="cb5" onclick="controlla(this,'cb',2)">
<input type="checkbox" id="cb6" onclick="controlla(this,'cb',2)">
Selezionare 3
<input type="checkbox" id="cc1" onclick="controlla(this,'cc',3)">
<input type="checkbox" id="cc2" onclick="controlla(this,'cc',3)">
<input type="checkbox" id="cc3" onclick="controlla(this,'cc',3)">
<input type="checkbox" id="cc4" onclick="controlla(this,'cc',3)">
<input type="checkbox" id="cc5" onclick="controlla(this,'cc',3)">
<input type="checkbox" id="cc6" onclick="controlla(this,'cc',3)">
Selezionare 4 (default - modificare maxChecked)
<input type="checkbox" id="cd1" onclick="controlla(this,'cd')">
<input type="checkbox" id="cd2" onclick="controlla(this,'cd')">
<input type="checkbox" id="cd3" onclick="controlla(this,'cd')">
<input type="checkbox" id="cd4" onclick="controlla(this,'cd')">
<input type="checkbox" id="cd5" onclick="controlla(this,'cd')">
<input type="checkbox" id="cd6" onclick="controlla(this,'cd')">
<input type="checkbox" id="cd7" onclick="controlla(this,'cd')">
<input type="checkbox" id="cd8" onclick="controlla(this,'cd')">
<input type="checkbox" id="cd9" onclick="controlla(this,'cd')">
</body>
</html>