locked
select all boxes ? RRS feed

  • Question

  • Hi all

    i have one check box in my page .. when i checked this checkbox the rest of the checkboxes has to checkin and vice versa.. using java script

    can any body help me out.. its very urgent for me..

    the first check box  is single and parent and rest of checkboxes are generated asper the number of items at runtime...

    Wednesday, February 16, 2011 2:19 PM

Answers

  • you can refer http://dotnet.aspx.cc/article/a8efc285-f0b1-4f8f-8e73-2b7d8724a47c/read.aspx

     

    or

    var checked = true;

    function checkAll()

    {

    boxs = document.getElementsByTagName("input")

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

    if(boxs[i].type=="checkbox" ) boxs[i].checked =  checked

    }

    checked= !checked

    }

     

    if you put all boxs in one table or div,you can do like this

    boxs = document.getElementById("divid").getElementsByTagName("input")


    【孟子E章】
    • Marked as answer by Vasu Thota Wednesday, February 23, 2011 6:40 AM
    Wednesday, February 23, 2011 1:35 AM

All replies

  • My recommendation would be to generate the JavaScript as well, and then assign it to the onchange event of the checkbox. The JavaScript should be pretty simple, so I won't bother explaining that here, but here are several things that I will just mention to keep in mind:

    1. If you are using ASP.NET (I don't know if you are or not, but this being an MSDN newsgroup I wouldn't find it unlikely), make sure you use the ClientId property of each checkbox when generating the JavaScript
    2. In order to allow the JavaScript to work for both checking and unchecking, assign the value of the main checkbox to each of the other checkboxes. Here is what the generated JavaScript will basicly look like:

    function CheckUncheckAll()
    {
       var ischecked=document.getElementById('chkMainCheckbox').checked;
       document.getElementById('chkCheckbox1').checked=ischecked;    //There will be a statement like this for all of the checkboxes
    }

    Hopefully this helps.


    Nathan Sokalski
    njsokalski@hotmail.com
    http://www.nathansokalski.com/

    "Vasu Thota" wrote in message news:5bc8a740-1cad-47ad-8ca1-4dafe1f31104@communitybridge.codeplex.com...

    Hi all

    i have one check box in my page .. when i checked this checkbox the rest of the checkboxes has to checkin and vice versa.. using java script

    can any body help me out.. its very urgent for me..

    the first check box  is single and parent and rest of checkboxes are generated asper the number of items at runtime...


    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
    Thursday, February 17, 2011 9:50 PM
  • you can refer http://dotnet.aspx.cc/article/a8efc285-f0b1-4f8f-8e73-2b7d8724a47c/read.aspx

     

    or

    var checked = true;

    function checkAll()

    {

    boxs = document.getElementsByTagName("input")

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

    if(boxs[i].type=="checkbox" ) boxs[i].checked =  checked

    }

    checked= !checked

    }

     

    if you put all boxs in one table or div,you can do like this

    boxs = document.getElementById("divid").getElementsByTagName("input")


    【孟子E章】
    • Marked as answer by Vasu Thota Wednesday, February 23, 2011 6:40 AM
    Wednesday, February 23, 2011 1:35 AM