SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member zackjenks's Avatar
    Join Date
    Aug 2006
    Location
    Portland, Oregon
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should do the trick...

    Code:
    // javascript
    function doCheckAll(onoff) 
    {
      var i, collection;
      collection = document.getElementsByName("check");
      for (i = 0; i < collection.length; i++) 
      {
        if (!onoff) collection[i].checked = false;
        else collection[i].checked = true;
      }
    }
    
    // html
    <input type="checkbox" name="selectAll" onclick="doCheckAll(this.checked);" />Select ALL
    
    <input type="checkbox" name="check" value="1" />
    <input type="checkbox" name="check" value="2" />
    <input type="checkbox" name="check" value="3" />

  2. #2
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by zackjenks
    This should do the trick...
    That's so wrong, it should be like this:
    Code:
    // javascript
    function doCheckAll(onoff) 
    {
      var i, collection;
      collection = document.getElementsByName("check");
      for (i = 0; i < collection.length; i++) 
      {
        if (!onoff) collection[i].checked = false;
        else collection[i].checked = true;
      }
    }
    
    // html
    <input type="checkbox" name="selectAll" onclick="doCheckAll(this.checked);" />Select ALL
    
    <input type="checkbox" name="check" value="1" />
    <input type="checkbox" name="check" value="2" />
    <input type="checkbox" name="check" value="3" />
    <input type="checkbox" name="check" value="4" />

  3. #3
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
      
    <script type="text/javascript">
    function doCheckAll(bu) {
      var el = document.getElementsByName("check");
      for (var i = 0; i < el.length; i++)   {    el[i].checked = bu;   }  }
    </script>
    </head>
    <body>
    <input type="checkbox" name="selectAll" onclick="doCheckAll(this.checked);" />Select ALL
    
    <input type="checkbox" name="check" value="1" />
    <input type="checkbox" name="check" value="2" />
    <input type="checkbox" name="check" value="3" />
    <input type="checkbox" name="check" value="4" />
    Bismillahirrahmanirrahîm
    Bizi doğru yola, kendilerine nimet verdiklerinin yoluna ilet; gazaba uğrayanların ve sapıklarınkine değil.

  4. #4
    SitePoint Zealot keith5885's Avatar
    Join Date
    Jun 2006
    Location
    at my computer
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why when I have

    PHP Code:
    echo '<input type="checkbox" name="check" id="' $COM_ID '" />'
    when listing my boxes then

    when I post that data from a form then try to retrieve it

    PHP Code:
    $COM_ID_value $_POST[$COM_ID]; 

    It does not pull any value?

    But when I change the name to the $COM_ID as well it works but then the javascript doesnt work?
    Thanks Sitepoint!

  5. #5
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should really create a new thread for this question.


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
  •