Results 1 to 3 of 3

Thread: checkbox array

  1. #1
    Join Date
    Nov 2010
    Posts
    115
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Default checkbox array

    Hi All,

    I am struck with javascript functionality. Can any one help me out from the following scenario.

    I am having a td where iam getting some names using foreach.


    <td align='center'> <input type="checkbox" name="variant[]" id="<? echo $Variant[Name]; ?>" value="<? echo $Variant[Name]; ?>"></td>

    iam having three different types of names and iam adding a new row when ever any row is inserted in database. iam checkaa functionality for every column.

    column A columnB columnC
    checkbox checkbox

    checkbox checkbox

    checkbox

    button1 button 2 button3

    the above is my scenario.

    all the checkbox i am getting is from the above td i wrote. if i select button1 i should be able to select all the checkboxes under column A. and the same for button2 and button 3. How can i do this.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Is there something about the buttons that ties or relates them to the checkboxes, like a shared class that no other input elements share, or are thay all the children of a parent element that contains no other checkboxes?

    If you don't know for sure, we need to see the actual generated HTML markup.

    If you do know, what is it?

    Alternatively we could create something like that as they are being retrieved/created by the server side code.

    We may still need to see the HTML code, better yet a link to the page.

    And as a side note, would jQuery be OK? In most cases it would be easier to write something like this in jQuery.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script type="text/javascript">
    /*<![CDATA[*/
    
    function Check(cb){
     var td=cb,table=cb,checked=cb.checked,index,rows,cells;
     while (td.parentNode&&td.nodeName.toUpperCase()!='TD'){
      td=td.parentNode;
     }
     index=td.cellIndex;
     while (table.parentNode&&table.nodeName.toUpperCase()!='TABLE'){
      table=table.parentNode;
     }
     rows=table.rows;
     for (var z0=0;z0<rows.length;z0++){
      cb=rows[z0].cells[index].getElementsByTagName('INPUT')[0];
      if (cb){
       cb.checked=checked;
      }
     }
    }
    
    /*]]>*/
    </script></head>
    
    <body>
    <table border="1">
      <tr>
        <td><input type="checkbox" name="" onclick="Check(this);" /></td>
        <td><input type="checkbox" name="" onclick="Check(this);" /></td>
      </tr>
      <tr>
        <td><input type="checkbox" name="" onclick="Check(this);" /></td>
        <td>''<td>
      </tr>
      <tr>
        <td><input type="checkbox" name="" onclick="Check(this);" /></td>
        <td><input type="checkbox" name="" onclick="Check(this);" /></td>
      </tr>
    </table>
    </form>
    </body>
    
    </html>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

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
  •