...

View Full Version : Hiding table rows.



Raider
01-28-2006, 06:38 PM
Hi, I've currently got a nice small JS script that hides whichever table row you want. Here it is:


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.

vwphillips
01-28-2006, 08:20 PM
<!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>

Raider
01-28-2006, 10:34 PM
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. :thumbsup:

vwphillips
01-29-2006, 12:19 AM
<!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>

Raider
01-29-2006, 12:47 AM
Thanks again. :)

That's exactly what I needed.

jaceq
03-14-2006, 04:39 PM
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...:)

vwphillips
03-14-2006, 10:49 PM
back tomorrow

vwphillips
03-15-2006, 06:30 PM
<!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>

NoYckl
11-02-2007, 06:44 PM
<!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!

NoYckl
11-12-2007, 01:42 PM
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.. :(



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum