Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    406
    Thanks
    0
    Thanked 0 Times in 0 Posts

    checking multiple checkboxes by clicking on another check box

    I have 2 set of check boxes. One check box says "Select all" and when the user checks on this check box, it should check a group of check boxes. THe only thing is I wouldnt know how many check boxes to be checked at one time. Can I do this in a loop?

    I wrote some thing like below, but as I said if I dont know how many check boxes to be checked, then I cannot write like this since this will write for a definite number of check boxes.

    <script language="javascript">
    function checkAll4() {
    document.info.all3.checked = true; }

    function checkOthers4() {
    if (document.info.all3.checked == fasle)
    {
    document.info.agri.checked = true;
    document.info.astro.checked = true;
    document.info.biosc.checked = true;
    document.info.chem.checked = true;
    document.info.comp.checked = true;
    }
    }
    </script>

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Heres an example:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function checkAll()
    {
    	for(var i = 0; i < document.forms[0].check.length; i++)
    	{
    		if(document.forms[0].check1.checked)
    		{
    			document.forms[0].check[i].checked = true;
    		}
    		else
    		{
    			document.forms[0].check[i].checked = false;
    		}
    	}
    }
    
    </script>
    <body>
    <form>
    <input type="checkbox" name="check1" onclick="checkAll();"><br>
    <input type="checkbox" name="check"><br>
    <input type="checkbox" name="check"><br>
    <input type="checkbox" name="check"><br>
    <input type="checkbox" name="check"><br>
    <input type="checkbox" name="check"><br>
    <input type="checkbox" name="check"><br>
    <input type="checkbox" name="check"><br>
    </form>
    </body>
    </html>

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    406
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Brandoe85!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •