Selecting multiple checkboxes with a single checkbox.

Discussion in 'Javascript' started by Eric, Oct 23, 2003.

  1. Eric

    Eric Guest

    Hi all,

    I have a form that generates a dynamic number of rows from a value
    passed in via querystring. I have a one static row in my form with a
    "master" checkbox that I have deemed "Select All:". I want to be able
    to select all and deselect all the other checkboxes beneath it in the
    column by clicking on it. I've gotten it partially working. I can
    click the "master" checkbox and it will set the .checked property of
    all the others to true. BUT how do I reverse the process and turn them
    all off? Here is my funcion:

    function selectAllInstall()
    {
    var frm;
    frm = document.frm;

    if (frm.chkCheckAllInstall.checked = true)
    {
    for (var i = 0; i < <%=dtlQty%>; i++)
    {
    frm.chkInstallReq.checked = true;
    }
    }

    if (frm.chkCheckAllInstall.checked = false)
    {
    for (var i = 0; i < <%=dtlQty%>; i++)
    {
    frm.chkInstallReq.checked = false;
    }
    }
    }

    HTML for the Main Checkbox:
    <td class="mnuHdr"><input type="checkbox" name="chkCheckAllInstall"
    onClick="selectAllInstall();"></td>

    Any ideas or suggestions would be greatly appreciated.

    Thanks.
     
    Eric, Oct 23, 2003
    #1
    1. Advertising

  2. Eric

    Oz Guest

    Here is a simple solution:

    <script language="javascript">
    function checkAll(master){
    var checked = master.checked;
    var col = document.getElementsByTagName("INPUT");
    for (var i=0;i<col.length;i++) {
    col.checked= checked;
    }
    }
    </script>

    Master: <input type="checkbox" onclick="checkAll(this)"><br>
    Slave1:<input type="checkbox" ><br>
    Slave2:<input type="checkbox" ><br>

    regards
    Mike




    "Eric" <> wrote in message
    news:...
    > Hi all,
    >
    > I have a form that generates a dynamic number of rows from a value
    > passed in via querystring. I have a one static row in my form with a
    > "master" checkbox that I have deemed "Select All:". I want to be able
    > to select all and deselect all the other checkboxes beneath it in the
    > column by clicking on it. I've gotten it partially working. I can
    > click the "master" checkbox and it will set the .checked property of
    > all the others to true. BUT how do I reverse the process and turn them
    > all off? Here is my funcion:
    >
    > function selectAllInstall()
    > {
    > var frm;
    > frm = document.frm;
    >
    > if (frm.chkCheckAllInstall.checked = true)
    > {
    > for (var i = 0; i < <%=dtlQty%>; i++)
    > {
    > frm.chkInstallReq.checked = true;
    > }
    > }
    >
    > if (frm.chkCheckAllInstall.checked = false)
    > {
    > for (var i = 0; i < <%=dtlQty%>; i++)
    > {
    > frm.chkInstallReq.checked = false;
    > }
    > }
    > }
    >
    > HTML for the Main Checkbox:
    > <td class="mnuHdr"><input type="checkbox" name="chkCheckAllInstall"
    > onClick="selectAllInstall();"></td>
    >
    > Any ideas or suggestions would be greatly appreciated.
    >
    > Thanks.
     
    Oz, Oct 24, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Honnen
    Replies:
    0
    Views:
    398
    Martin Honnen
    Jul 18, 2008
  2. Mark B
    Replies:
    3
    Views:
    2,750
    Mark B
    Mar 30, 2009
  3. Rick C

    Selecting multiple CheckBoxes in a CheckBoxList

    Rick C, Jun 29, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    363
    Rick C
    Jun 29, 2004
  4. Jez

    Selecting/deselecting checkboxes

    Jez, Jul 17, 2003, in forum: Javascript
    Replies:
    4
    Views:
    121
  5. JL
    Replies:
    7
    Views:
    211
    Thomas 'PointedEars' Lahn
    Mar 10, 2008
Loading...

Share This Page