Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Hiding table rows.

    Hi, I've currently got a nice small JS script that hides whichever table row you want. Here it is:
    Code:
    function toggle(hidethis) {
     if( document.getElementById(hidethis).style.display=='none' ){
       document.getElementById(hidethis).style.display = '';
     }else{
       document.getElementById(hidethis).style.display = 'none';
     }
    }
    It works like a charm, but I was wondering if there was any way of making the table row FADE OUT instead of abrubtly disappearing... I'm totally useless when it comes to JS, so any help will be appreciated.

    Thanks

    PS: I've searched the forum and haven't seen anything like this, so sorry if it's a repost.

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,522
    Thanks
    3
    Thanked 508 Times in 495 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    var Obj,Lok
    
    function Hide(obj){
     if (Lok){ return; }
     Loc=true;
     Obj=obj;
     Obj.ht=Obj.offsetHeight;
     Obj.style.position='relative';
     Obj.style.overflow='hidden';
     HideDo();
    }
    
    function HideDo(){
     Obj.style.height=(Obj.ht--)+'px';
     if (Obj.ht>20){ setTimeout('HideDo()',20); }
     else {
      Obj.style.display='none';
      Lok=false;
     }
    }
    
    
    //-->
    </script>
    </head>
    
    <body>
    <table width="100" border="1">
    <tbody   >
     <tr height=100 onclick="Hide(this);" >
      <td>1111111111111111</td>
     </tr>
     <tr >
      <td>1111111111111111</td>
     </tr>
     <tr height=100 onclick="Hide(this);" >
      <td>1111111111111111</td>
     </tr>
    </tbody>
    
    </table>
    </body>
    
    </html>

  • #3
    New Coder
    Join Date
    Aug 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh! That's perfect! Now, like I said before, I have no clue when it comes to javascript. Is there a way to do the exact opposite? What I mean is, once a cell is hidden, is there a way for it to appear again using the same method?

    Again, thanks a lot vwphillips, that's exactly what I was looking for.

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,522
    Thanks
    3
    Thanked 508 Times in 495 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    // by Vic Phillips (28-Jan-2005) http://www.vicsjavascripts.org.uk
    
    // Application Notes
    // Executed by event call to zxcHide(zxcobj,zxcdir,zxcminh,zxcdly)
    // where
    // parameter 0 = object or object ID name               (object or string)
    // parameter 1 = < 1 reduce height, > 1 increase height (digits)
    // parameter 2 = the minimum height                     (digits)
    // parameter 3 = optional delay (default 100mSec)       (digits)
    
    
    // Functional Code NO NEED to Change
    
    var zxcOOPCnt=0
    
    function zxcHide(zxcobj,zxcdir,zxcminh,zxcdly){
     if (typeof(zxcobj)=='string'){ zxcobj=document.getElementById(zxcobj);}
     if (!zxcobj.oop){ zxcobj.oop=new zxcOOPHS(zxcobj,zxcdir,zxcminh,zxcdly); }
     clearTimeout(zxcobj.oop.to);
     zxcobj.oop.dir=zxcdir;
     zxcobj.oop.delay=zxcdly||zxcobj.oop.delay;
     if (zxcdir>0){ zxcobj.style.display=''; }
     zxcobj.oop.cngheight();
    }
    
    function zxcOOPHS(zxcm,zxcdir,zxcminh,zxcdly){
     this.obj=zxcm.style;
     this.obj.position='relative';
     this.obj.overflow='hidden';
     this.ref='zxchs'+zxcOOPCnt;
     window[this.ref]=this;
     this.minh=zxcminh;
     this.maxh=zxcm.offsetHeight;
     this.dir=zxcdir;
     if (zxcdir<0){ this.cnt=this.maxh; }
     else { this.cnt=this.minh; }
     this.delay=zxcdly||100;
     this.to=null;
     zxcOOPCnt++;
    }
    
    zxcOOPHS.prototype.cngheight=function(){
     if ((this.dir<0&&this.cnt>this.minh)||(this.dir>0&&this.cnt<this.maxh)){
      this.obj.height=(this.cnt+=this.dir)+'px';
      this.setTimeOut("cngheight();",this.delay);
     }
     else if (this.dir<0){ this.obj.display='none'; }
     else if (this.dir>0){ this.obj.height=this.maxh+'px'; }
    
    }
    
    zxcOOPHS.prototype.setTimeOut=function(zxcf,zxcd){
     this.to=setTimeout("window."+this.ref+"."+zxcf,zxcd);
    }
    
    
    //-->
    </script>
    </head>
    
    <body>
    <table width="150" border="1">
    <tbody   >
     <tr >
      <td align="center" >
      <img src="http://www.vicsjavascripts.org.uk/StdImages/Up1.gif" onclick="zxcHide('Row2',-1,20,5);" >
      <img src="http://www.vicsjavascripts.org.uk/StdImages/Down1.gif" onclick="zxcHide('Row2',1,20);" >
      </td>
     </tr>
     <tr height=100 id="Row2" onclick="zxcHide(this,-1,20);" >
      <td>1111111111111111</td>
     </tr>
     <tr >
      <td align="center" >
      <img src="http://www.vicsjavascripts.org.uk/StdImages/Up1.gif" onclick="zxcHide('Row3',-1,20,100);" >
      <img src="http://www.vicsjavascripts.org.uk/StdImages/Down1.gif" onclick="zxcHide('Row3',1,20,10);" >
      </td>
     </tr>
     <tr height=100 id="Row3" >
      <td>1111111111111111</td>
     </tr>
    </tbody>
    
    </table>
    </body>
    
    </html>

  • #5
    New Coder
    Join Date
    Aug 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks again.

    That's exactly what I needed.

  • #6
    New to the CF scene
    Join Date
    Mar 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi there,
    Your code ig great!
    What about if I'd like to hide few rows of table with a single click? Your code is working for one table row which is located below...

  • #7
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,522
    Thanks
    3
    Thanked 508 Times in 495 Posts
    back tomorrow
    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/

  • #8
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,522
    Thanks
    3
    Thanked 508 Times in 495 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    // by Vic Phillips (15-March-2005) http://www.vicsjavascripts.org.uk
    
    // Application Notes
    // Executed by event call to zxcHide(zxcobj,zxcdir,zxcminh,zxcdly)
    // where
    // parameter 0 = object or object ID name               (object or string)
    // parameter 1 = < 1 reduce height, > 1 increase height (digits)
    // parameter 2 = the minimum height                     (digits)
    // parameter 3 = optional delay (default 100mSec)       (digits)
    
    
    // Functional Code NO NEED to Change
    
    var zxcOOPCnt=0
    
    function zxcHide(){
     var zxcargs=zxcHide.arguments;
     var zxcobj;
     for (zxc0=0;zxc0<zxcargs.length;zxc0++){
      if (typeof(zxcargs[zxc0][0])=='string'){ zxcobj=document.getElementById(zxcargs[zxc0][0]);}
      else { zxcobj=zxcargs[zxc0][0]; }
      if (!zxcobj.oop){ zxcobj.oop=new zxcOOPHS(zxcobj,zxcargs[zxc0][1],zxcargs[zxc0][2],zxcargs[zxc0][3]); }
      clearTimeout(zxcobj.oop.to);
      zxcobj.oop.dir=zxcargs[zxc0][1]||-zxcobj.oop.dir;
      zxcobj.oop.delay=zxcargs[zxc0][3]||zxcobj.oop.delay
      if (zxcobj.oop.dir>0){ zxcobj.style.display=''; }
      zxcobj.oop.cngheight();
     }
    }
    
    function zxcOOPHS(zxcm,zxcdir,zxcminh,zxcdly){
     this.obj=zxcm.style;
     this.obj.position='relative';
     this.obj.overflow='hidden';
     this.ref='zxchs'+zxcOOPCnt;
     window[this.ref]=this;
     this.minh=zxcminh;
     this.maxh=zxcm.offsetHeight;
     this.dir=zxcdir;
     if (zxcdir<0){ this.cnt=this.maxh; }
     else { this.cnt=this.minh; }
     this.delay=zxcdly||100;
     this.to=null;
     zxcOOPCnt++;
    }
    
    zxcOOPHS.prototype.cngheight=function(){
     if ((this.dir<0&&this.cnt>this.minh)||(this.dir>0&&this.cnt<this.maxh)){
      this.obj.height=(this.cnt+=this.dir)+'px';
      this.setTimeOut("cngheight();",this.delay);
     }
     else if (this.dir<0){ this.obj.display='none'; }
     else if (this.dir>0){ this.obj.height=this.maxh+'px'; }
    
    }
    
    zxcOOPHS.prototype.setTimeOut=function(zxcf,zxcd){
     this.to=setTimeout("window."+this.ref+"."+zxcf,zxcd);
    }
    
    
    //-->
    </script>
    </head>
    
    <body>
    <table width="150" border="1">
    <tbody   >
     <tr >
      <td align="center" >
      <img src="http://www.vicsjavascripts.org.uk/StdImages/Up1.gif" onclick="zxcHide(['Row2',-1,20,5]);" >
      <img src="http://www.vicsjavascripts.org.uk/StdImages/Down1.gif" onclick="zxcHide(['Row2',1,20]);" >
      </td>
     </tr>
     <tr height=100 id="Row2" onclick="zxcHide(this,-1,20);" >
      <td>1111111111111111</td>
     </tr>
     <tr >
      <td align="center" >
      <img src="http://www.vicsjavascripts.org.uk/StdImages/Up1.gif" onclick="zxcHide(['Row3',-1,20,100],['Row4',-1,20,10]);" >
      <img src="http://www.vicsjavascripts.org.uk/StdImages/Down1.gif" onclick="zxcHide(['Row3',1,20,100],['Row4',1,20,10]);" >
      </td>
     </tr>
     <tr height=100 id="Row3" >
      <td>1111111111111111</td>
     </tr>
     </tr>
     <tr height=100 id="Row4" >
      <td>1111111111111111</td>
     </tr>
    </tbody>
    
    </table>
    </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/

  • #9
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by vwphillips View Post
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    // by Vic Phillips (15-March-2005) http://www.vicsjavascripts.org.uk
    
    // Application Notes
    // Executed by event call to zxcHide(zxcobj,zxcdir,zxcminh,zxcdly)
    // where
    // parameter 0 = object or object ID name               (object or string)
    // parameter 1 = < 1 reduce height, > 1 increase height (digits)
    // parameter 2 = the minimum height                     (digits)
    // parameter 3 = optional delay (default 100mSec)       (digits)
    
    
    // Functional Code NO NEED to Change
    
    var zxcOOPCnt=0
    
    function zxcHide(){
     var zxcargs=zxcHide.arguments;
     var zxcobj;
     for (zxc0=0;zxc0<zxcargs.length;zxc0++){
      if (typeof(zxcargs[zxc0][0])=='string'){ zxcobj=document.getElementById(zxcargs[zxc0][0]);}
      else { zxcobj=zxcargs[zxc0][0]; }
      if (!zxcobj.oop){ zxcobj.oop=new zxcOOPHS(zxcobj,zxcargs[zxc0][1],zxcargs[zxc0][2],zxcargs[zxc0][3]); }
      clearTimeout(zxcobj.oop.to);
      zxcobj.oop.dir=zxcargs[zxc0][1]||-zxcobj.oop.dir;
      zxcobj.oop.delay=zxcargs[zxc0][3]||zxcobj.oop.delay
      if (zxcobj.oop.dir>0){ zxcobj.style.display=''; }
      zxcobj.oop.cngheight();
     }
    }
    
    function zxcOOPHS(zxcm,zxcdir,zxcminh,zxcdly){
     this.obj=zxcm.style;
     this.obj.position='relative';
     this.obj.overflow='hidden';
     this.ref='zxchs'+zxcOOPCnt;
     window[this.ref]=this;
     this.minh=zxcminh;
     this.maxh=zxcm.offsetHeight;
     this.dir=zxcdir;
     if (zxcdir<0){ this.cnt=this.maxh; }
     else { this.cnt=this.minh; }
     this.delay=zxcdly||100;
     this.to=null;
     zxcOOPCnt++;
    }
    
    zxcOOPHS.prototype.cngheight=function(){
     if ((this.dir<0&&this.cnt>this.minh)||(this.dir>0&&this.cnt<this.maxh)){
      this.obj.height=(this.cnt+=this.dir)+'px';
      this.setTimeOut("cngheight();",this.delay);
     }
     else if (this.dir<0){ this.obj.display='none'; }
     else if (this.dir>0){ this.obj.height=this.maxh+'px'; }
    
    }
    
    zxcOOPHS.prototype.setTimeOut=function(zxcf,zxcd){
     this.to=setTimeout("window."+this.ref+"."+zxcf,zxcd);
    }
    
    
    //-->
    </script>
    </head>
    
    <body>
    <table width="150" border="1">
    <tbody   >
     <tr >
      <td align="center" >
      <img src="http://www.vicsjavascripts.org.uk/StdImages/Up1.gif" onclick="zxcHide(['Row2',-1,20,5]);" >
      <img src="http://www.vicsjavascripts.org.uk/StdImages/Down1.gif" onclick="zxcHide(['Row2',1,20]);" >
      </td>
     </tr>
     <tr height=100 id="Row2" onclick="zxcHide(this,-1,20);" >
      <td>1111111111111111</td>
     </tr>
     <tr >
      <td align="center" >
      <img src="http://www.vicsjavascripts.org.uk/StdImages/Up1.gif" onclick="zxcHide(['Row3',-1,20,100],['Row4',-1,20,10]);" >
      <img src="http://www.vicsjavascripts.org.uk/StdImages/Down1.gif" onclick="zxcHide(['Row3',1,20,100],['Row4',1,20,10]);" >
      </td>
     </tr>
     <tr height=100 id="Row3" >
      <td>1111111111111111</td>
     </tr>
     </tr>
     <tr height=100 id="Row4" >
      <td>1111111111111111</td>
     </tr>
    </tbody>
    
    </table>
    </body>
    
    </html>
    vwphillips, thank you!
    Can you post this code with no Delay option? i want to click on the image and the rows disapear instantly.
    Thank you, Great Work!

  • #10
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you post this script without delay option?
    In rows with a lot of content there's a lot of delay before the row go hidden..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •