Publisher: Sigit purnomo kangsigit.com@gmail.com

Define Limits Voted on Checkbox Using JavaScript

I am very happy to share with you through this blog, especially if you like it. At this post, I had prepared source code to create limits checkbox. It is useful to control options that you set up on the form.

By default, I set it to three checked. Of course you can change it according to their individual needs.
<form id="setOption" name="setOption">
<input type="checkbox" name="state" /> USA<br />
<input type="checkbox" name="state" /> Indonesian<br />
<input type="checkbox" name="state" /> Japan<br />
<input type="checkbox" name="state" /> China<br />
<input type="checkbox" name="state" /> France<br />
<script type="text/javascript">
** Get more script: http://www.askedboss.com **
function checkboxlimit(optionGroup, limit){
var optionGroup=optionGroup
var limit=limit
for (var i=0; i<optionGroup.length; i++){
var checkedState=0
for (var i=0; i<optionGroup.length; i++)
checkedState+=(optionGroup[i].checked)? 1 : 0
if (checkedState>limit){
alert("You can only select a maximum of "+limit+" checkboxes") // notif
// Especially for which it should be placed under a checkbox
checkboxlimit(document.forms.setOption.state, 3) // set of three

Test this code

no image
Add Comments
Click Here to Add Comments

No Comment