

In the above example we have restricted maximum number of selection user can make. Restricting the sum of selected values of the checkboxes. Here j carries the serial number of the checkbox which was last clicked.ĭemo of checkbox limit by using getElementByName() → This line below inside the function uses that and unchecks that particular checkbox.

So on every click of the checkbox we will pass the serial number of the checkbox to the function to tell which one is the last one clicked. Here once the fourth one is clicked by the user the function shows a message and after that it removes or uncheck the last checkbox ( the fourth one ) the user has clicked. We have used onclick event of checkbox to trigger the function which checks the number of checkbox clicked. You can read the checkbox details like its status and how to handle array of checkbox here. Limiting number of selection user can check from a group of checkboxes by using JavaScript
