SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast athena's Avatar
    Join Date
    Apr 2002
    Location
    Vancouver, Canada
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Check All button script for use in PHP

    [as suggested, I'm cross-posting this from the PHP forum...]


    I'm using this bit of code I found online to do a check all/uncheck all button:

    HTML Code:
    <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>

    My problem is that if the input checkboxes look like this:

    HTML Code:
    <input name="delChecked" type="checkbox" value="$itemcode">
    The check all script works but PHP doesn't recognize that delChecked is an array. And if I do this...

    HTML Code:
    <input name="delChecked[]" type="checkbox" value="$itemcode">
    PHP reads delChecked as an array but the Javascript doesn't work.


    any ideas?

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How/where are you calling the check function? The parameter appears to be an array of input objects, are you sure that's what you're passing? The call should be something like

    onclick="check(document.getElementsByName('delChecked[]'));"

  3. #3
    SitePoint Enthusiast athena's Avatar
    Join Date
    Apr 2002
    Location
    Vancouver, Canada
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry, guess that's kinda essential...

    HTML Code:
    <input type=button value="Check All" onClick="this.value=check(this.form.delChecked)">

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah that won't work with the [], you'll need to use:

    this.value=check(document.getElementsByName('delChecked[]'));

    that should work.

  5. #5
    SitePoint Enthusiast athena's Avatar
    Join Date
    Apr 2002
    Location
    Vancouver, Canada
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yup, it did.
    thanks!


Bookmarks

Posting Permissions

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