implement "select all" button to select all checkboxes

Discussion in 'ASP General' started by Matt, Jan 11, 2004.

  1. Matt

    Matt Guest

    In ASP page, there is a "SELECT ALL" button, when user click it, it will
    select all checkboxes. I am not sure should I use client-side code to do
    that? the following is my approach but it didnt work.

    <script language="JavaScript">
    function selectAllCheckBox()
    { //alert(document.addzone.c1.value);
    document.addzone.c1.value = "on";
    }
    </script>

    <P><input type="checkbox" name="c1">
    <P><input type="button" onclick="selectAllCheckBox()">


    any ideas??
     
    Matt, Jan 11, 2004
    #1
    1. Advertising

  2. document.addzone.c1.checked = true

    --
    Roji. P. Thomas
    --------------------------------------
    "Matt" <> wrote in message
    news:...
    > In ASP page, there is a "SELECT ALL" button, when user click it, it will
    > select all checkboxes. I am not sure should I use client-side code to do
    > that? the following is my approach but it didnt work.
    >
    > <script language="JavaScript">
    > function selectAllCheckBox()
    > { //alert(document.addzone.c1.value);
    > document.addzone.c1.value = "on";
    > }
    > </script>
    >
    > <P><input type="checkbox" name="c1">
    > <P><input type="button" onclick="selectAllCheckBox()">
    >
    >
    > any ideas??
    >
    >
     
    Roji. P. Thomas, Jan 11, 2004
    #2
    1. Advertising

  3. Matt

    Roland Hall Guest

    "Matt" wrote:
    : In ASP page, there is a "SELECT ALL" button, when user click it, it will
    : select all checkboxes.
    That is not possible unless you pass the form on the URL or the header and
    then test when the page is loaded. ASP is server-side.

    : I am not sure should I use client-side code to do
    : that?
    You should.

    : the following is my approach but it didnt work.
    : <script language="JavaScript">
    : function selectAllCheckBox()
    : { //alert(document.addzone.c1.value);
    : document.addzone.c1.value = "on";
    : }
    : </script>
    :
    : <P><input type="checkbox" name="c1">
    : <P><input type="button" onclick="selectAllCheckBox()">

    1. language= on client-side is deprecated. Use type="text/javascript"
    instead.
    2. document.addzone.c1.value = "on"; is not correct for three reasons.
    a. addzone is not present. If you just didn't show that and have the
    following then it is ok.

    <form id="addzone" name="addzone">
    <P><input type="checkbox" name="c1">
    <P><input type="button" onclick="selectAllCheckBox()">
    </form>

    b. You do not have a value set for c1 so value="".
    c. You do not test a value to see if a checkbox has been checked. This will
    work:
    document.addzone.c1.checked=true;

    Also, you're only showing one checkbox. If you want a way to select all at
    once, then you can use different IDs and name all of them the same name and
    use it as an array.

    <html>
    <head>
    <title></title>
    <script type="text/javascript">
    function selectAllCheckBox() {
    var formCol='', elCol='';
    formCol = document.forms['addzone'];
    elCol = formCol.c1;
    for(i=0;i<elCol.length;i++) {
    elCol(i).checked=true;
    }
    }
    </script>
    </head>
    <body>
    <form id="addzone" name="addzone">
    <input type="checkbox" id="chk1" name="c1" value="1">One<br />
    <input type="checkbox" id="chk2" name="c1" value="2">Two<br />
    <input type="checkbox" id="chk3" name="c1" value="3">Three<br />
    <input type="button" value="Check All Boxes" onclick="selectAllCheckBox()">
    </form>
    </body>
    </html>

    Clean up:
    <p> should have </p>
    Your button should have a value.

    --
    Roland

    This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose.
    -Technet Knowledge Base-
    http://support.microsoft.com/default.aspx?scid=fh;EN-US;kbhowto&sd=TECH&ln=EN-US&FR=0
    -Technet Script Center-
    http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/default.asp
    -MSDN Library-
    http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, Jan 11, 2004
    #3
    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. BTHOMASinOHIO
    Replies:
    2
    Views:
    165
  2. Al Knowles

    How to select all or deselect all checkboxes in datagrid...

    Al Knowles, Dec 1, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    244
    Al Knowles
    Dec 1, 2003
  3. Stafarian

    How to use Button control, with checkboxes in a datagrid

    Stafarian, Oct 15, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    125
    Phillip Williams
    Oct 16, 2005
  4. Amit D.Shinde

    Select All Checkboxes

    Amit D.Shinde, Jul 7, 2004, in forum: ASP General
    Replies:
    1
    Views:
    128
  5. Gumtree
    Replies:
    3
    Views:
    261
    Matt Kruse
    Nov 10, 2004
Loading...

Share This Page