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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a hand 1

Status
Not open for further replies.

DANZIG

Technical User
Mar 8, 2001
142
US
Hellos,
How could I modify the code below to open allow only one table to be open at a time?
Code:
function table_actions(tbl) {
   if (document.getElementById(tbl).style.display != "") {
      document.getElementById(tbl).style.display = "";
   }
   else {
      document.getElementById(tbl).style.display = "none";
   }
}
IE user clicks table2 while table1 is open, table1 then closes and table2 opens.


Thanks, Danzig
 
Assign Id for each table - tbl1, tbl2, tbl3 etc. Then:
Code:
<script language="javascript">
function showtable( iId )
{	for(i=1; (oTab=document.getElementById("tbl" + i)); i++)
		oTab.style.display= iId==i? "block": "none";
}
</script>
 
So if my onclick event is:
Code:
onclick="table_actions('Table1')"

Then it would look like this?
Code:
<script language="javascript">
function table_actions(tbl)
{    for(i=1; (oTab=document.getElementById(tbl)); i++)
        oTab.style.display= tbl=="Table"+i? "block": "none";
}
</script>

I tried that but it seems to lock my browser for some reason??


Thanks, Danzig
 
You have infinite for() loop. Try:
Code:
{    for(i=1; (oTab=document.getElementById([b]"Table"+i[/b])); i++)
 
Thanks Very much vongrunt.
Star for you 8)


Thanks, Danzig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top