[Javascript] Checkbox challenge
Shawn Milo
milo at linuxmail.org
Thu May 6 14:53:48 CDT 2004
Try some modification of this:
In each checkbox: onclick="threeOnly(this)"
function threeOnly(lastChecked){
var numChecked = 0;
for (x=0;x<document.forms[0].elements.length;x++){
if ((document.forms[0].elements[x].type == 'checkbox') && (document.forms[0].elements[x].value == 'on')){
numChecked++;
}
}
if (numChecked > 3){
lastChecked.checked = false;
alert('Please uncheck another option before choosing this one. You may select a maxumim of three');
}
}
Note:
Untested, and I sometimes get confused about how you refer to the status of a
checkbox between ASP and Javascript, so my syntax may be screwy, but here's
something I think you can work with.
Shawn
More information about the Javascript
mailing list