Help: Show - Hide

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

Join Date: Jun 2007
Posts: 71
Reputation: Pro2000 is an unknown quantity at this point 
Solved Threads: 1
Pro2000's Avatar
Pro2000 Pro2000 is offline Offline
Junior Poster in Training

Help: Show - Hide

 
0
  #1
Jul 25th, 2007
Peace, Can you help me with Show And Hide?:
I made an Input text I want to hide it, And I want to show it if I click on a button. How can I do it?
Thanks.
The great scientist see his web-site:
http://www.elnaggarzr.com/en
I'm sure that will be good for you!
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,648
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Help: Show - Hide

 
0
  #2
Jul 25th, 2007
It can be done in two ways. The difference between the two methods is obvious: one of them(visibility) doesn't change the page layout while the other(display) does.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <script>
  4. function hide()
  5. {
  6. var elem = document.getElementById('myP');
  7. elem.style.display = 'none';
  8. }
  9. function show()
  10. {
  11. var elem = document.getElementById('myP');
  12. elem.style.display = '';
  13. }
  14.  
  15. function hide2()
  16. {
  17. var elem = document.getElementById('myP2');
  18. elem.style.visibility = 'hidden';
  19. }
  20. function show2()
  21. {
  22. var elem = document.getElementById('myP2');
  23. elem.style.visibility = 'visible';
  24. }
  25. </script>
  26. </head>
  27. <body>
  28. <form>
  29. <h2 align="center">Using the display property of CSS</h2>
  30. <p id="myP">Here is some text which I want to hide</p>
  31. <br />
  32. <input type="button" onclick="hide();" value="Hide" />
  33. <input type="button" onclick="show();" value="Show" />
  34.  
  35. <h2 align="center">Using the visibility property of CSS</h2>
  36. <p id="myP2">Here is some text which I want to hide</p>
  37. <br />
  38. <input type="button" onclick="hide2();" value="Hide" />
  39. <input type="button" onclick="show2();" value="Show" />
  40. </form>
  41. </body>
  42. </html>
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 2
Reputation: Markweb is an unknown quantity at this point 
Solved Threads: 0
Markweb Markweb is offline Offline
Newbie Poster

Re: Help: Show - Hide

 
0
  #3
Jan 17th, 2009
Easiest solution is to use one javascript function to show and hide.

Example :

  1. <a onclick ="javascript : ShowHide('HiddenDiv')" href="javascript:;" >Show/Hide</a>
  2.  
  3. <div class="mid" id="HiddenDiv" style="DISPLAY: none" >
  4. This text was hidden
  5. </div>
  6.  
  7. <script language="JavaScript">
  8. function ShowHide(divId)
  9. {
  10. if(document.getElementById(divId).style.display == 'none')
  11. {
  12. document.getElementById(divId).style.display='block';
  13. }
  14. else
  15. {
  16. document.getElementById(divId).style.display = 'none';
  17. }
  18. }
  19. </script>

For more details visit article
How to show and hide HTML elements using Javascript
Last edited by peter_budo; Jan 18th, 2009 at 2:03 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
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



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

©2003 - 2009 DaniWeb® LLC