SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Select all checkboxes

    I need a script to select and deselect all checkboxes in a form, but it must allow me to name the checkboxes whatever[] for PHP reasons. Can anyone help?

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  2. #2
    Spam Can Kill!!! Disk-t's Avatar
    Join Date
    Jul 2001
    Location
    n/a
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    <script>
    function getit() {
    document.former.checkbox2.checked=true;
    document.former.checkbox3.checked=true;
    document.former.checkbox4.checked=true;
    document.former.checkbox5.checked=true;
    document.former.checkbox6.checked=false;
    }
    function getit1() {
    document.former.checkbox1.checked=false;
    document.former.checkbox2.checked=false;
    document.former.checkbox3.checked=false;
    document.former.checkbox4.checked=false;
    document.former.checkbox5.checked=false;

    }
    </script>
    <form name="former">
    <p>Select All: <input type="checkbox" name="checkbox1"[0] value="ON" onClick="getit()" style="color: #FF0000; background-color: #000000; border-style: dotted">
    &nbsp;
    </p>
    <p>Deselect:&nbsp;<input type="checkbox" name="checkbox6"[1] value="ON" onClick="getit1()" style="color: #FF0000; background-color: #000000; border-style: dotted">
    </p>
    <p>1. <input type="checkbox" name="checkbox2"[2] value="ON" style="color: #FF0000; background-color: #000000; border-style: dotted">
    </p>
    <p>2. <input type="checkbox" name="checkbox3"[3] value="ON" style="color: #FF0000; background-color: #000000; border-style: dotted">
    </p>
    <p>3. <input type="checkbox" name="checkbox4"[4] value="ON" style="color: #FF0000; background-color: #000000; border-style: dotted">
    </p>
    <p>4. <input type="checkbox" name="checkbox5"[5] value="ON" style="color: #FF0000; background-color: #000000; border-style: dotted">

    </form></p>

  3. #3
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My script should work fine for this: http://anarchos.xs.mw/formtricks.phtml
    ck :: bringing chris to the masses.

  4. #4
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you both. Anarchos I will use your script as it is perfect for what I wanted, Disk-t your example answered another question I had

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  5. #5
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Sean,

    You might also be interested in the "Get CheckBox Selections" script/tutorial at my site, which not only allows you to get all boxes, but also all but checked boxes. That is, the user can check one or two boxes, then check the 'inverse' box and all checked values are reversed so that the one or two checked boxes are now the only unchecked boxes.

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  6. #6
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I'll check it out

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature


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
  •