HTML Tables in JSP

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Jul 2009
Posts: 93
Reputation: AshtonHogan is an unknown quantity at this point 
Solved Threads: 1
AshtonHogan AshtonHogan is offline Offline
Junior Poster in Training

HTML Tables in JSP

 
0
  #1
Jul 29th, 2009
Hi,

I'm trying to create a page that contains a table that is hidden initially (on page startup). Later, when a link is clicked, the table should show permanently. The problem I am having, however, is that when I click on the link, the table shows for a second and then dissapears again. Below is the code:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <head>
  2. <script type="text/javascript">
  3. var n=0;
  4. </script>
  5. </head>
  6. <body onload="tableOff('myTable')">
  7.  
  8. <!-- Extend/Collapse Tables Script -->
  9. <script type="text/javascript">
  10. function tableOff(Object) {
  11. if (n==0) {
  12. document.getElementById(Object).style.display="none";
  13. }
  14. n++;
  15. }
  16.  
  17. function tableOn(Object) {
  18. if (n >=1) {
  19. document.getElementById(Object).style.display="";
  20. }
  21. }
  22. </script>
  23. <!-- Extend/Collapse Tables Script -->
  24.  
  25. <table id="myTable">
  26. <tr>
  27. <td>
  28. My Table
  29. </td>
  30. </tr>
  31. </table>
  32.  
  33. <a href="this.jsp" onClick="tableOn('myTable')">Click Me</a>
  34.  
  35. </body>

I know incrementing a variable may not be the most efficient way, but for now if I can get that to work then it will be easy to change that to boolean at a later stage...
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: HTML Tables in JSP

 
0
  #2
Jul 29th, 2009
Hi Ashton,

in the <head> section of your page, you may apply this format:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. <!--
  3. // Basic Sample
  4.  
  5.  
  6. var tableOn = function( obj ) {
  7. document.getElementById( obj ).style.display = "table";
  8. };
  9.  
  10. onload = function() {
  11. document.getElementById("myTable").style.display = "none";
  12. };
  13. // -->
  14. </script>

do the same instance as you call your tableOn( tableID ) function...
<a href="javascript:void(0);" onclick="tableOn('myTable');">Show Table</a>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 275 | Replies: 1
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC