944,104 Members | Top Members by Rank

Ad:
Jul 25th, 2007
0

Help: Show - Hide

Expand Post »
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.
Similar Threads
Reputation Points: 44
Solved Threads: 23
Posting Whiz
Pro2000 is offline Offline
350 posts
since Jun 2007
Jul 25th, 2007
0

Re: Help: Show - Hide

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>
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006
Jan 17th, 2009
0

Re: Help: Show - Hide

Easiest solution is to use one javascript function to show and hide.

Example :

html Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Markweb is offline Offline
2 posts
since Dec 2008
Feb 12th, 2010
0
Re: Help: Show - Hide
if i want to select the three option button and fourth option butoon if i click thna show the radio button accound to condtion
Reputation Points: 10
Solved Threads: 1
Newbie Poster
sumit1893 is offline Offline
2 posts
since Feb 2010
Feb 12th, 2010
0
Re: Help: Show - Hide
where is my answer
Reputation Points: 10
Solved Threads: 1
Newbie Poster
sumit1893 is offline Offline
2 posts
since Feb 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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: Check Request headers of a Browser.
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: JAVASCRIPT Page Refresh





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


Follow us on Twitter


© 2011 DaniWeb® LLC