SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Evangelist jazztie's Avatar
    Join Date
    Mar 2001
    Location
    the Netherlands
    Posts
    519
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    checking multiple checkboxes with one click

    I would like to know if it is possible to check multiple checkboxes with one click.

    Say, for instance, that I have the following code:
    PHP Code:
    $Query mysql_query("SELECT * FROM relation");
    if (
    mysql_num_rows($Query)){
      while (
    $rows mysql_fetch_array($Query)); {
      
    extract($rows);
      print 
    "<input type=checkbox value=$id name='sendmail'> $Name"
    }

    As you can see, I don't know exactly how many checkboxes will be printed. But I want one button to click, to select or deselect all the checkboxes.
    And maybe, if it is possible, look at other database-info to check only the ones that are "$active = '1'". (for instance)

    Could anyone help me with this one?
    Thanx!

  2. #2
    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)
    This is javascript, not PHP, so you'd do something like:
    <input type="checkbox" onClick="checkEm('sendmail')" >
    function checkEm(name){
    for (var i = 0; i < document.yourform[name].length; i++)
    document.yourform[name][i].checked = true;
    }
    ck :: bringing chris to the masses.


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
  •