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 4 of 4
  1. #1
    New Coder hedbanger's Avatar
    Join Date
    Jun 2002
    Location
    vallejo, ca
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts

    more "check all" checkboxes

    i got this code from this board here a while back and have been attempting to adapt it to my needs.

    it's for an intranet and only needs to work on i.e.

    selecting from a list of groups will create a list of subgroups which can be further refined by checking their boxes. there will be a checkboxes and a button for each of the dynamically created lists.

    the first problem is that after the first button is clicked, the next one has to be clicked twice. once to focus it and once to click it. this is very annoying. how do i correct this?
    here's the code:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title>check it out</title>
    <SCRIPT LANGUAGE="JavaScript">
    <!-- // Begin
    var checkflag = "false";
    function check(field) {
    if (checkflag == "false") {
    for (i = 0; i < field.length; i++) {
    field[i].checked = true;}
    checkflag = "true";
    return "Uncheck All"; }
    else {
    for (i = 0; i < field.length; i++) {
    field[i].checked = false; }
    checkflag = "false";
    return "Check All"; }
    }
    // End -->
    </script>
    </head>
    <body>
    <FORM ACTION="" METHOD="POST" ENCTYPE="application/x-www-form-urlencoded">
    <!-- -->
    <br>
    <table width="150" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
    <td align="center">SET 1</td>
    </tr>
    <tr>
    <td align="center">
    <input name="button1"type="button" style="COLOR: #24559E; BACKGROUND-COLOR: #ffffff" onClick="this.value=check(this.form.elements['SRP2'])" value="Check All">
    <br>
    <br>
    <br>
    <br>
    <br>
    </td>
    </tr>
    <tr>
    <td align="left">
    <input type="checkbox" name="SRP2" value="1">
    A<br>
    <input type="checkbox" name="SRP2" value="2">
    B<br>
    <input type="checkbox" name="SRP2" value="3">
    C<br>
    </td>
    </tr>
    </table>
    <p>&nbsp;</p>
    <p><br>
    </p>
    </form>
    <FORM ACTION="" METHOD="POST" ENCTYPE="application/x-www-form-urlencoded">
    <table width="150" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
    <td align="center">SET 2</td>
    </tr>
    <tr>
    <td align="center">
    <input name="button2"type="button" style="COLOR: #24559E; BACKGROUND-COLOR: #ffffff" onClick="this.value=check(this.form.elements['SRP2[]2'])" value="Check All">
    <br>
    <br>
    <br>
    <br>
    <br>
    </td>
    </tr>
    <tr>
    <td align="left">
    <input type="checkbox" name="SRP2[]2" value="1">
    &Xi; <br>
    <input type="checkbox" name="SRP2[]2" value="2">
    &Zeta;<br>
    <input type="checkbox" name="SRP2[]2" value="3">
    &Omega;<br>
    </tr>
    </table>
    </form>
    </body>
    </html>
    jf~ if you're not part of the solution, you're part of the precipitate.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    You've got two forms, and only one set of flags. Try this:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title>check it out</title>
    <SCRIPT LANGUAGE="JavaScript">
    <!-- // Begin
    function check_uncheck_all(button, name) {
    var box, e = 0, grp = button.form[name];
    while (box = grp[e++]) box.checked = (button.value == 'Check All');
    return (button.value == 'Check All') ? 'Uncheck All' : 'Check All';
    }
    // End -->
    </script>
    </head>
    <body>
    <FORM ACTION="" METHOD="POST" ENCTYPE="application/x-www-form-urlencoded">
    <!-- -->
    <br>
    <table width="150" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
    <td align="center">SET 1</td>
    </tr>
    <tr>
    <td align="center">
    <input name="button1"type="button" style="COLOR: #24559E; BACKGROUND-COLOR: #ffffff; WIDTH: 100px;" onClick="this.value=check_uncheck_all(this,'SRP2')" value="Check All">
    <br>
    <br>
    <br>
    <br>
    <br>
    </td>
    </tr>
    <tr>
    <td align="left">
    <input type="checkbox" name="SRP2" value="1">
    A<br>
    <input type="checkbox" name="SRP2" value="2">
    B<br>
    <input type="checkbox" name="SRP2" value="3">
    C<br>
    </td>
    </tr>
    </table>
    <p> </p>
    <p><br>
    </p>
    </form>
    <FORM ACTION="" METHOD="POST" ENCTYPE="application/x-www-form-urlencoded">
    <table width="150" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
    <td align="center">SET 2</td>
    </tr>
    <tr>
    <td align="center">
    <input name="button2"type="button" style="COLOR: #24559E; BACKGROUND-COLOR: #ffffff; WIDTH: 100px;" onClick="this.value=check_uncheck_all(this,'SRP2[]2')" value="Check All">
    <br>
    <br>
    <br>
    <br>
    <br>
    </td>
    </tr>
    <tr>
    <td align="left">
    <input type="checkbox" name="SRP2[]2" value="1">
    ? <br>
    <input type="checkbox" name="SRP2[]2" value="2">
    ?<br>
    <input type="checkbox" name="SRP2[]2" value="3">
    O<br>
    </tr>
    </table>
    </form>
    </body>
    </html>

  • #3
    New Coder hedbanger's Avatar
    Join Date
    Jun 2002
    Location
    vallejo, ca
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    excellent!
    thanks.
    jf~ if you're not part of the solution, you're part of the precipitate.

  • #4
    New Coder hedbanger's Avatar
    Join Date
    Jun 2002
    Location
    vallejo, ca
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i've got this script loading dynamically after submitting a search.
    i find that some of the results return with only 1 subclass and therefore only 1 checkbox.
    the checkall/uncheckall button doesn't function for this.

    it would be best to omit the button when there is only a single checkbox. how would i go about this?
    thanks.
    jf~ if you're not part of the solution, you're part of the precipitate.


  •  

    Posting Permissions

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