943,769 Members | Top Members by Rank

Ad:
Jul 29th, 2009
0

HTML Tables in JSP

Expand Post »
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...
Similar Threads
Reputation Points: 7
Solved Threads: 1
Posting Whiz in Training
AshtonHogan is offline Offline
209 posts
since Jul 2009
Jul 29th, 2009
0

Re: HTML Tables in JSP

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>
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: need help changing background color of an iframe
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: need javascript coding!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC