Automatically check/uncheck multiple checkboxes

javascript , checkbox , multiple United Kingdom
This is a comment thread discussing Automatically check/uncheck multiple checkboxes
  • 12 years ago
    Hi! In my program, I have multiple check boxs.(more the 10) But i give rights to select 2 check boxs, If i select more then 2 check boxs, I want to display alert message. Please any one post me modle program in ASP and javascript. Please very very urgent.... any only help me... My javascript program: (Its not working) function myFunction() { var canSu = true; //Check how many checkboxes are on the form boxes = document.frmUpdate.chkboxes.length //Check for all the checkboxes on the form using the loop var chkCnt=0; for (i = 0; i < boxes; i++) { if (document.frmUpdate.chkboxes[i].checked) { chkCnt++; } } if(chkCnt >= 2) { return false; } return true; } By Susan.
  • 12 years ago
    hi Susan, Keep the autopost back property of checkbox to true. and whenever a checkobox is checked then use a looping statement(like: for loop) to check the state of all the checkboxs on your form. And keep a counter variable to count the no. of check boxes checked. If the counter increases than 2 then display the message. To scan throught all the checkboxes on your form, lets say the check boxes are on a panel then: foreach(control c in panel.controls) { if(c is checkbox) { checkbox cbx = new checkbox(); cbx = panel.findcontrol(; if(cbx.checked.equals(true) { // increment the counter // check if counter is less than 2 or not // perform the necessary task } } } Regards, Royal
  • 12 years ago
    What I need is simple: I’d like a checkbox that UNCHECKS the other checkboxes in a single array. I'd be grateful if someone can suggest a short javascript that would do this without affecting other checkboxes or radio buttons within the same form.

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Linux is only free if your time has no value” - Jamie Zawinski