Blog: Tag Archives: checkboxes

Javascript – Limit Number of checkboxes

Posted On:

<title>Katy Whitton Web Development - Limit Checkboxes</title>
<script language="JavaScript">
var ItemCount=0 
var MaxItemCount=2

function setItems(item)


if (ItemCount>MaxItemCount)
  alert('You may only choose '+MaxItemCount+' Industries') 
<body><br />Select a Maxmimum of 2 items:
<form name="form" target="blank">
Item 1 <input type="checkbox" name="item1" value="item1" onclick="setItems(this)"><br />
Item 2 <input type="checkbox" name="item2" value="item2" onclick="setItems(this)"><br />
Item 3 <input type="checkbox" name="item3" value="item3" onclick="setItems(this)"><br />
Item 4 <input type="checkbox" name="item4" value="item4" onclick="setItems(this)"><br />
Item 5 <input type="checkbox" name="item5" value="item5" onclick="setItems(this)"><br />