Solved

Change / Hide text field on click

Posted on 2008-10-29
4
4,032 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 125 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 125 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

Industry Leaders: 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

When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
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…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

726 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