Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Change / Hide text field on click

Posted on 2008-10-29
4
Medium Priority
?
4,035 Views
Last Modified: 2012-05-05
Hi,

I have the below code which works well to show the hidden text field but once the field is changed to inline-block it cannot be reverted back to hidden.

Can you please provide suggestions? Thanks.
function Change(){
if (document.getElementById( "myId" ).style.display = "none")
	{
		document.getElementById( "myId" ).style.display = "inline-block"; 
	}
else
 
if (document.getElementById( "myId" ).style.display = "inline-block")
	{
		document.getElementById( "myId" ).style.display = "none"; 
	}
}
 
<BODY>
 
<tr>
 
<td>
<input type="button" onclick="Change();" value="Click Me">
</td>
 
<!--<input type="button" onclick="Hide();" value="Java Hide"> -->
 
<td><input type=text id="myId" style="display:none"></input></td>
 
</tr>
 
</BODY>
</HTML>

Open in new window

0
Comment
Question by:Rassac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22829148
try:
<html>
<head>
<script type="text/javascript">
function Change(){
if (document.getElementById( "myId" ).style.display == "none")
      {
            document.getElementById( "myId" ).style.display = "inline-block"; 
      }
else if (document.getElementById( "myId" ).style.display == "inline-block")
      {
            document.getElementById( "myId" ).style.display = "none"; 
      }
}
 </script>
 </head>
<BODY>
 
<tr>
 
<td>
<input type="button" onclick="Change();" value="Click Me">
</td>
 
<!--<input type="button" onclick="Hide();" value="Java Hide"> -->
 
<td><input type=text id="myId" style="display:none"></input></td>
 
</tr>
 
</BODY>
</HTML>

Open in new window

0
 
LVL 6

Assisted Solution

by:Chorch
Chorch earned 500 total points
ID: 22829151
Hello,

I use this funtion which can show/hide many different elements in page:

<script type="text/javascript">
var state = 'none';
function showhide(divname) {
      if (state == 'block') {
            state = 'none';
      }
      else {
            state = 'block';
      }
      if (document.all) {
            eval("document.all." + divname + ".style.display = state");
      }
      if (document.layers) {
            document.layers[divname].display = state;
            
      }
      if (document.getElementById &&!document.all) {
            document.getElementById(divname).style.display = state;
      }
}
</script>
===================
<input type="button" onclick="showhide('myId');" value="Click Me">

Regards
0
 

Author Closing Comment

by:Rassac
ID: 31511084
thanks :)
0
 
LVL 82

Expert Comment

by:hielo
ID: 22831022
you are welcome
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CSS3 Custom checkboxes This article shows how to style the checkbox form element using only CSS. Works in: Chrome, FF, Safari, Opera, IE9+ Uses modernizr.js to check for :checked pseudo class, falling back to plain old checkboxes (IE8 and bel…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question