Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hide a table

Status
Not open for further replies.

MaddogC

Programmer
Dec 4, 2003
134
GB
I am using the following javascript to show or hide a table when the user clicks on a check box.

if (document.post.C3.checked)
{
document.getElementById("table1").style.visibility = "visible";
}
else
{
document.getElementById("table1").style.visibility = "hidden";
}

However, there are further tables after the show/Hide section, if I hide the table, there is a gap to my next table. Is there another property apart from hidden which will prevent this?
 
Yep cuz the browser still renders tyhe table but makes it invisible
Should use display="none"
Code:
if (document.post.C3.checked)
   {
     document.getElementById("table1").style.display = "";
   }
  else
    {
      document.getElementById("table1").style.display = "none";
  }

________
George, M
 
This almost works. The screen adjusts correctly, however the contents of the table now don't display.

Do I need to change the following line from "" to "block" or similar?

document.getElementById("table1").style.display = "";
 
Maybe you need to check your table content first, maybe it's no data there.
The code as it is works for shure.

________
George, M
 
I need to combine the two statements, which is almost there!
The only problem now, is that when the page first opens, there is the blank gap. Where can I set the property so that it doesn't display when it first opens?


if (document.post.C1.checked)
{
document.getElementById("area2").style.display="";
document.getElementById("area2").style.visibility = "visible";
}
else
{
document.getElementById("area2").style.display="none";
document.getElementById("area2").style.visibility = "hidden";
}
 
Aha well then your problem it's on the TABLE tag
should be something like this.
Code:
<table id=table1 style=&quot;display:none&quot;>


</table>
.....
if (document.post.C3.checked)
   {
     document.getElementById(&quot;table1&quot;).style.display = &quot;&quot;;
   }
  else
    {
      document.getElementById(&quot;table1&quot;).style.display = &quot;none&quot;;
  }

Use the first code, the problem was that you had the table style=&quot;visibility:hidden&quot; and so it would remain the white gap. but changing into display:none would work.
Also any display value that is not none will show your table.


________
George, M
 
You need encapsulate the table into the <div></div> and make this object Hidden, this eliminate the gap on the page.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top