How can i hide the columns whith JavaScript without bugs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • greendoc
    New Member
    • Mar 2008
    • 4

    How can i hide the columns whith JavaScript without bugs


    This example is exactly what i need, but it's have a bug when using Opera (9.25 on my computer)
    Does anybody now some other code like that?
  • greendoc
    New Member
    • Mar 2008
    • 4

    #2
    YAHOO ! Just need to replacing 'block' by ''
    Now i search the way to do this without named element..

    Comment

    • greendoc
      New Member
      • Mar 2008
      • 4

      #3
      The problem is solved

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Can you share the final solution for the benefit of others? Thanks!

        Comment

        • greendoc
          New Member
          • Mar 2008
          • 4

          #5
          Originally posted by acoder
          Can you share the final solution for the benefit of others? Thanks!
          Shure.. the code is:
          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">
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <title>Show/Hide columns for Ciklum CRM</title>
          <script language="javascript">
            function show_hide_column(btn,col_no) {
          	btn   = document.forms['tcol'].elements[btn];
          	stl = btn.checked ? '' : 'none';
              var tbl  = document.getElementById('table_id');
              var rows = tbl.getElementsByTagName('tr');
          
              for (var row=0; row<rows.length;row++) {
                var cels = rows[row].getElementsByTagName('td');
                cels[col_no-1].style.display=stl;
              }
            }
          </script>
          </head>
          
          <body>
          <table id="table_id" width="100%" border=1>
          <tr>
          <td bgcolor="#666666" class="bold">column 1 text</td>
          <td bgcolor="#99FF00">column 2 text</td>
          <td bgcolor="#CC6633" class="italic">column 3 text</td>
          <td bgcolor="#FFFF33">column 4 text</td>
          </tr>
          <tr>
          <td bgcolor="#666666" class="bold">column 1 text</td>
          <td bgcolor="#99FF00">column 2 text</td>
          <td bgcolor="#CC6633" class="italic">column 3 text</td>
          <td bgcolor="#FFFF33">column 4 text</td>
          </tr>
          <tr>
          <td bgcolor="#666666" class="bold">column 1 text</td>
          <td bgcolor="#99FF00">column 2 text</td>
          <td bgcolor="#CC6633" class="italic">column 3 text</td>
          <td bgcolor="#FFFF33">column 4 text</td>
          </tr>
          </table>
          <p>&nbsp;</p>
          <p>&nbsp;</p>
          <form name="tcol" onsubmit="return false">
          Hide/Show columns
          <input type=checkbox name="col1" onclick="show_hide_column(this.name,1)" checked> 1
          <input type=checkbox name="col2" onclick="show_hide_column(this.name,2)" checked> 2
          <input type=checkbox name="col3" onclick="show_hide_column(this.name,3)" checked> 3
          <input type=checkbox name="col4" onclick="show_hide_column(this.name,4)" checked> 4
          </form>
          </body>
          </html>

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Thanks for posting.

            Comment

            Working...