Selecting multiple checkboxes with a single checkbox.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric

    Selecting multiple checkboxes with a single checkbox.

    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 selectAllInstal l()
    {
    var frm;
    frm = document.frm;

    if (frm.chkCheckAl lInstall.checke d = true)
    {
    for (var i = 0; i < <%=dtlQty%>; i++)
    {
    frm.chkInstallR eq[i].checked = true;
    }
    }

    if (frm.chkCheckAl lInstall.checke d = false)
    {
    for (var i = 0; i < <%=dtlQty%>; i++)
    {
    frm.chkInstallR eq[i].checked = false;
    }
    }
    }

    HTML for the Main Checkbox:
    <td class="mnuHdr"> <input type="checkbox" name="chkCheckA llInstall"
    onClick="select AllInstall();"> </td>

    Any ideas or suggestions would be greatly appreciated.

    Thanks.
  • Oz

    #2
    Re: Selecting multiple checkboxes with a single checkbox.

    Here is a simple solution:

    <script language="javas cript">
    function checkAll(master ){
    var checked = master.checked;
    var col = document.getEle mentsByTagName( "INPUT");
    for (var i=0;i<col.lengt h;i++) {
    col[i].checked= checked;
    }
    }
    </script>

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

    regards
    Mike




    "Eric" <eking@unumprov ident.com> wrote in message
    news:11460e25.0 310231148.13c1d d2a@posting.goo gle.com...[color=blue]
    > 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 selectAllInstal l()
    > {
    > var frm;
    > frm = document.frm;
    >
    > if (frm.chkCheckAl lInstall.checke d = true)
    > {
    > for (var i = 0; i < <%=dtlQty%>; i++)
    > {
    > frm.chkInstallR eq[i].checked = true;
    > }
    > }
    >
    > if (frm.chkCheckAl lInstall.checke d = false)
    > {
    > for (var i = 0; i < <%=dtlQty%>; i++)
    > {
    > frm.chkInstallR eq[i].checked = false;
    > }
    > }
    > }
    >
    > HTML for the Main Checkbox:
    > <td class="mnuHdr"> <input type="checkbox" name="chkCheckA llInstall"
    > onClick="select AllInstall();"> </td>
    >
    > Any ideas or suggestions would be greatly appreciated.
    >
    > Thanks.[/color]


    Comment

    Working...