mark chopin: checkbox auswahl limitieren

Beitrag lesen

So zum Beispiel:

---------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>Checkboxen</title>
  <script language="JavaScript" type="text/javascript">
  <!--
   function check (elementID) {
    var formID = document.forms["one"];
     var count = 0;
    var maxNumber = 5;

for (i=0; i<formID.length; i++) {
     if (formID.elements[i].type=="checkbox" && formID.elements[i].checked==true && count<=maxNumber) {
      count++;
     }
    }

if (count>maxNumber) {
     elementID.checked = false;
     alert ("Es dürfen nur maximal "+maxNumber+" Checkboxen ausgwählt werden!");
    }
   }
  //-->
  </script>
</head>

<body>

<form name="one" action="something">
   <input type="checkbox" onclick="check(this);"><input type="checkbox" onclick="check(this);">
   <input type="checkbox" onclick="check(this);"><input type="checkbox" onclick="check(this);">
   <input type="checkbox" onclick="check(this);"><input type="checkbox" onclick="check(this);">
   <input type="checkbox" onclick="check(this);"><input type="checkbox" onclick="check(this);">
  </form>

</body>
</html>
---------------------------------------------------------------