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

Join Date: Jul 2008
Posts: 147
Reputation: anuj576 is an unknown quantity at this point 
Solved Threads: 10
anuj576 anuj576 is offline Offline
Junior Poster

<div> help!!

 
0
  #1
Aug 18th, 2008
hey guys,
I have made a web page which comprises of two divisions.The first div is used to display a table which shows the inhouse trainess and the other div also displays a table which shows the outside trainess.
Initially when the page loads both the divisions are hidden.I have also made two buttons which show respective divisions.if one division is visible then the other is hidden and vice-versa.
The problem I am having is that one division is displayed at the bottom of the other of the other division which means that when the top division is hidden and the other is visible,the div is displayed leaving some space at the top which doen't look nice.
What i want is that if both the divisions can be displayed at the same place.
PLEASE HELP
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 381
Reputation: langsor is an unknown quantity at this point 
Solved Threads: 33
langsor langsor is offline Offline
Posting Whiz

Re: <div> help!!

 
0
  #2
Aug 19th, 2008
When you use the css declaration visibility to hide elements, it does not change the page layout, so you will end up with unwanted whitespace in your layout -- which is my guess what you are doing.

Use the declaration: display: none|block
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <html>
  3. <head>
  4. <style type="text/css">
  5. #tbl1,
  6. #tbl2 {
  7. display: none; /* REQUIRED */
  8. width: 200px; /* emulate content for example */
  9. height: 200px; /* emulate content for example */
  10. border: 1px solid indigo; /* emulate content for example */
  11. background: silver; /* emulate content for example */
  12. }
  13. #tbl2 {
  14. background: yellow; /* emulate content for example */
  15. }
  16. </style>
  17. <script type="text/javascript">
  18. function toggle_tables ( show, hide ) {
  19. var active = document.getElementById( show ).style.display = 'block';
  20. var hidden = document.getElementById( hide ).style.display = 'none';
  21. }
  22. </script>
  23. </head>
  24. <body>
  25. <input type="button" onclick="toggle_tables('tbl1','tbl2')" value="table 1" />
  26. <input type="button" onclick="toggle_tables('tbl2','tbl1')" value="table 2" />
  27. <div id="tbl1"> ... table one content goes here ... </div>
  28. <div id="tbl2"> ... table two content goes here ... </div>
  29. </body>
  30. </html>

Hope this helps

P.S. You could skip the <div> wrappers and just place those ids on the tables if you want to.
Last edited by langsor; Aug 19th, 2008 at 4:47 pm.
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: <div> help!!

 
0
  #3
Aug 20th, 2008
Pardon me if im bein rushy on this 1. Just a quick overview to the issue on how to work with those div tags! And hope it brighten u up...


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2.  
  3. <html>
  4.  
  5. <head>
  6.  
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  8. <title>Manipulating the table</title>

  1. <style type="text/css">
  2. form { margin: 6px; padding: 2px; }
  3. form input { margin: 0 2px 0 0; padding: 0; }
  4.  
  5. #wrap { position: absolute; top: 60%; }
  6. .samp { position: absolute; left: 10px; }
  7.  
  8. .samp td { background-color: gold; color: bronze; font-size: 20px; font-weight: bold; }
  9. .samp table { width: 50%; background-color: dimgrey; }
  10. </style>

  1. <script type="text/javascript">
  2. <!-- BEGIN HIDING
  3. function tbl0()
  4. { emp = [ 'name1', 'name2', 'name3' ];
  5. epos = ['item1', 'item2', 'item3' ];
  6. var btn = document.getElementsByTagName('input')[0];
  7. div = document.getElementsByTagName('div')[0];
  8.  
  9. del = document.getElementsByTagName('div')[1];
  10. div.removeChild(del);
  11. div1 = document.createElement('div');
  12. var tbl = document.createElement('table');
  13. var tblbody = document.createElement('tbody');
  14.  
  15. for ( var i = 0; i < 3; i++ )
  16. { var row = document.createElement('tr');
  17. var cell = document.createElement('td');
  18. var cell2 = document.createElement('td');
  19. var _emp = document.createTextNode(emp[i]);
  20. var _epos = document.createTextNode(epos[i]);
  21. cell.appendChild(_emp);
  22. row.appendChild(cell);
  23. cell2.appendChild(_epos);
  24. row.appendChild(cell2);
  25. tblbody.appendChild(row); }
  26. tbl.appendChild(tblbody);
  27. div1.appendChild(tbl);
  28. div.insertBefore(btn);
  29. div.appendChild(div1);
  30. tbl.setAttribute('border', '2');
  31. div1.setAttribute('class', 'samp');
  32. div1.setAttribute('id', 'mdiv');
  33.  
  34. /* Lets clock the user instead of using those classes! Just change the time value 4 how long do you want the table to stay in place */
  35.  
  36. stop = setTimeout('hide()', 5000);
  37. }
  38.  
  39. function hide()
  40. { clearTimeout(stop);
  41. div.removeChild(div1);
  42. var ndiv = document.createElement('div');
  43. div.appendChild(ndiv);
  44.  
  45. }
  46.  
  47. function tbl1()
  48. {
  49. /* Simply rewrite another code on this one, that will represent new date to the 2nd table */
  50. return tbl0();
  51. }
  52. //Hope this brighten you up!
  53. //Have fun on your script
  54. // Done Hiding -->
  55. </script>
  1. </head>
  2. <body>
  3. <div>
  4. <div>&nbsp;
  5. </div>
  6. </div>
  7.  
  8. <div id="wrap">
  9. <form name="myform">
  10. <input name="b1" onclick="tbl0();" type="button" value="Table1" />
  11. <input name="b2" onclick="tbl1();" type="button" value="Table2" />
  12. </div>
  13. </form>
  14. </body>
  15. </html>
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC