|
Using JavaScript to Restrict the Number of Check Boxes Selected
Welcome to Hooked On Phobics!Here's the JavaScript that checks the number of activated check boxes:
<SCRIPT LANGUAGE="JavaScript">
<!--
// Use the maxChecked variable to set the maximum number that can be checked
var maxChecked = 3
var totalChecked = 0
function CountChecked(field) {
if (field.checked)
totalChecked += 1
else
totalChecked -= 1
//
if (totalChecked > maxChecked) {
alert ("You can't check more than three boxes, silly!")
field.checked = false
totalChecked = maxChecked
}
}
function ResetCount(){
totalChecked = 0
}
//-->
</SCRIPT>
Copyright © 1995-2008 Paul McFedries and Logophilia Limited |