Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Collapse Expand with Image

Status
Not open for further replies.

sandra45

Technical User
Apr 3, 2003
72
ID
Hi, I have one image that I want to expand/show or collapse/hide some text boxes, labels of <td>, and button such as reset and submit. Can anyone help me please? Thanks.

Regards,
Sandra
 
use this

function hide(e,v){
document.getelementbyid(e).style.visibility = v
}

and call it using

hide('myhtmlelement','visible')

hide('myhtmlelement','hidden')

hth

simon
 
I enclose part of my code below. As you can see, I have a form which will take some data from the text boxes. If the user needs to add data, they will click on the image below test.gif to expand the text and text box. If not, the text and text box and submit/reset buttons will stay hidden. Can you let me know where to insert the code you mention into my code? Thanks.

<FORM action=test.asp method=post name=frmtest id=frmtest>

<table cellpadding=2 cellspacing=3 width=&quot;85%&quot; border=0 bgcolor=gold align=center>
<tr>
<td align=middle><font color=white size=5><b>Add Data

<IMG align=absmiddle border=0 hspace=1 style=&quot;cursor:hand&quot; src=&quot;../test.gif&quot;></b></font></td></tr>
</table>
<table border=0 cellpadding=0 cellspacing=0 width=&quot;85%&quot; bgcolor=lightgoldenrodyellow align=center>
<tr>
<td nowrap style=&quot;PADDING-left: 35px&quot; width=30% id=1><b>Name</b></td>
<td width=&quot;70%&quot;><INPUT maxLength=30 name=txtName size=30 id=2></td>
</tr><tr height=5><td></td></tr>
</form>
 
add the function within the head tags:
<head>
<script type=&quot;text/javascript&quot;>
<!--
function hide(e,v){
document.getelementbyid(e).style.visibility = v
}
//-->
</script>

and use this:


<FORM action=test.asp method=post name=frmtest id=frmtest>

<table cellpadding=2 cellspacing=3 width=&quot;85%&quot; border=0 bgcolor=gold align=center>
<tr>
<td align=middle><font color=white size=5><b>Add Data
<a href=&quot;javascript:hide('myTable','visible')&quot;>
<IMG align=absmiddle border=0 hspace=1 src=&quot;../test.gif&quot;></a></b></font></td></tr>
</table>
<table id=&quot;myTable&quot; border=0 cellpadding=0 cellspacing=0 width=&quot;85%&quot; bgcolor=lightgoldenrodyellow align=center style=&quot;visibility:hidden;&quot;>
<tr>
<td nowrap style=&quot;PADDING-left: 35px&quot; width=30% id=1><b>Name</b></td>
<td width=&quot;70%&quot;><INPUT maxLength=30 name=txtName size=30 id=2></td>
</tr><tr height=5><td></td></tr>
</table>
</form>

hth

simon
 
Hi Simon, many thanks. However, I still get an error message:
A Runtime Error occurred.
Line: 0
Error: Object expected.

Microsoft Script Editor points the error to this line:
<HTML><SCRIPT LANGUAGE=javascript>var __w=hide('myTable','visible');if(__w!=null)document.write(__w);

What does it mean? And why does the script open a new window to show the table (with the address: javascript:hide('myTable','visible') vid:1-1), NOT on the same page where the image located?

Regards,
Sandra
 
var __w=hide('myTable','visible');

if(__w!=null)document.write(__w);

you are trying to hide an element that has not been created yet.

try this:

<body onload=&quot;init&quot;>

function init(){
var __w=hide('myTable','visible');
if(__w!=null)document.write(__w);
}

i cant see what you are trying to do - but the function 'hide' does not return anything!

simon



 
Hi Simon, still the same error. I'm trying to have the image to show or hide table together with its contents, based on the code above, the screen will look like this more or less:

Add Data (Image test.gif is here)
Name (txtName text box is here)

So when the user clicks test.gif image, then Name and txtName text box will be shown or hidden.

Regards,
Sandra
 
You need to simplify.

function hide(f,e){
document.forms(f).elements(e).style.visibility = (document.forms(f).elements(e).style.visibility == 'hidden')?'hidden':'visible';
}

<a href=&quot;javascript:hide('myForm','myInput')&quot;>
<img border=&quot;0&quot; src=&quot;myimage.gif&quot;>
</a>
<form name=&quot;myForm&quot;>
<input name=&quot;myInput&quot; style=&quot;visibility : visible;&quot;>
</form>


simon
 
Hi Simon, I still get the same error message. I've changed the code using div instead for all objects inside a form and it seems to work fine. However, does not work in Netscape 7.1 for the following codes:

document.all
document.getElementById
document.layers[obj].visibility = 'visible'

Any idea?

Regards,
Sandra
 
What's the point in me suggesting something when you are going to do something else anyway - post some code, I dont have time to waste trying to figure out what you are trying to do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top