This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

toggle checkbox group when the max limit is reached

Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suppose i have 10 checkboxes and i allow the user to check max of 4 checkboxes.
When the limit is reached i.e. 4, i need to disable all the other checkboxes
and when i uncheck anyone (now only 3 are checked) all the checkboxes should be enabled

Here's the code which i tried

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<script type="text/javascript">

function checkboxlimit(checkgroup,max,min){
var checkgroup=checkgroup
var onlycheckgroup;

for (var i=0; i<checkgroup.length; i++){

var checkedcount=0

for (var i=0; i><checkgroup.length; i++){
checkedcount+=(checkgroup[i].checked)? 1 : 0
alert("checkedcount is "+checkedcount)

if (checkedcount==max){
var a=checkgroup[i].checked;
alert("only checked "+a);
alert("onlycheckgroup "+onlycheckgroup);

alert("in for loop");








<input type="checkbox" name="selectedItems" id="check" onclick="checkboxlimit(selectedItems,2)";/> <c:out value="John"/> <input type="checkbox" name="selectedItems" id="check" onclick="checkboxlimit(selectedItems,2)";/> <c:out value="Smith"/> <input type="checkbox" name="selectedItems" id="check" onclick="checkboxlimit(selectedItems,2)";/> <c:out value="Peter"/> <input type="checkbox" name="selectedItems" id="check" onclick="checkboxlimit(selectedItems,2)";/> <c:out value="Angel"/>



please help
Posts: 9695
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Madhvi welcome to javaranch

please Use Code Tags when you post a source code. You can edit your message using button and then add code tags to it and also indent the code properly. Also what happens when you run this code??
Posts: 67651
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without the code tags, it's unlikely most people will bother to try and read your post.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic