?
Solved

hiding table initially and displaying it  when clicked on a hyperlink in html page

Posted on 2005-03-29
6
Medium Priority
?
313 Views
Last Modified: 2011-09-20


Hi

My HTMl page is having a table with 2 colums and 5 rows and it has some content in it. but I want to hide this table untill the user clicks on the showtable hyperlink. This hyperlink should show the table below the hyperlink in the same page itself, instead of opening a new page. If the user doesnt  click the hyperlink the table should not be visible.

I am trying with onClick ="somefunct()" for the hyperlink but donno how to disable the table and enable the table inside the "somefunc()"

Is there any way to disable the table. let me know...  

Thanks
0
Comment
Question by:pacchureddy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 32

Accepted Solution

by:
Batalf earned 400 total points
ID: 13654268
<script>
function showHideTable(linkObj){
    var obj = document.getElementById('myTable');
    if(obj.style.display=='none'){
        obj.style.display='block';
        linkObj.innerHTML = 'Hide table';        
    }else{
        obj.style.display='none';
        linkObj.innerHTML = 'Show table';
    }

}
</style>
<a href="#" onclick="showHideTable(this)">Show table</a>
<table id="myTable">
<tr><td><p>Row 1</td><td><p>Row 1</td></tr>
<tr><td><p>Second row</td><td><p>Row 2</td></tr>
</table>
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13654281
WIthout errors:-)

<script>
function showHideTable(linkObj){
    var obj = document.getElementById('myTable');
    if(obj.style.display=='none'){
        obj.style.display='block';
        linkObj.innerHTML = 'Hide table';        
    }else{
        obj.style.display='none';
        linkObj.innerHTML = 'Show table';
    }

}
</script>
<a href="#" onclick="showHideTable(this)">Show table</a>
<table id="myTable" style="display:none">
<tr><td><p>Row 1</td><td><p>Row 1</td></tr>
<tr><td><p>Second row</td><td><p>Row 2</td></tr>
</table>
0
 
LVL 25

Assisted Solution

by:archrajan
archrajan earned 100 total points
ID: 13654329
u shud have return false

<a href="#" onclick="showHideTable(this);return false;">Show table</a>
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 32

Expert Comment

by:Batalf
ID: 13654354
Thank you!

Yes, the return false; I usual seem to forget that.

<script>
function showHideTable(linkObj){
    var obj = document.getElementById('myTable');
    if(obj.style.display=='none'){
        obj.style.display='block';
        linkObj.innerHTML = 'Hide table';        
    }else{
        obj.style.display='none';
        linkObj.innerHTML = 'Show table';
    }

}
</script>
<a href="#" onclick="showHideTable(this);return false">Show table</a>
<table id="myTable" style="display:none">
<tr><td><p>Row 1</td><td><p>Row 1</td></tr>
<tr><td><p>Second row</td><td><p>Row 2</td></tr>
</table>
0
 

Author Comment

by:pacchureddy
ID: 13656956
wow that is cool...

but I have many tables not just one.. and I have given this code in my html soo its hiding the first table whose id is myTable what abt the other tables......  can you just remodify a bit so that all the tables would be hidden...

thanks
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13657006
This is the same code for 3 tables:


<script>
function showHideTable(linkObj,tableObj){
    var obj = document.getElementById(tableObj);
    if(obj.style.display=='none'){
        obj.style.display='block';
        linkObj.innerHTML = 'Hide table';        
    }else{
        obj.style.display='none';
        linkObj.innerHTML = 'Show table';
    }

}
</script>
<a href="#" onclick="showHideTable(this,'myTable');return false">Show table</a><br>
<table id="myTable" style="display:none">
<tr><td><p>Row 1</td><td><p>Row 1</td></tr>
<tr><td><p>Second row</td><td><p>Row 2</td></tr>
</table>
<a href="#" onclick="showHideTable(this,'myTable2');return false">Show table</a><br>
<table id="myTable2" style="display:none">
<tr><td><p>Row 1</td><td><p>Row 1</td></tr>
<tr><td><p>Second row</td><td><p>Row 2</td></tr>
</table>
<a href="#" onclick="showHideTable(this,'myTable3');return false">Show table</a><br>
<table id="myTable3" style="display:none">
<tr><td><p>Row 1</td><td><p>Row 1</td></tr>
<tr><td><p>Second row</td><td><p>Row 2</td></tr>
<tr><td><p>Second row</td><td><p>Row 2</td></tr>
<tr><td><p>Second row</td><td><p>Row 2</td></tr>
<tr><td><p>Second row</td><td><p>Row 2</td></tr>
</table>
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question