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!

Layer onClick 1

Status
Not open for further replies.

iralh

Programmer
Sep 20, 2001
12
US
Hi,

I have been trying to get a layer displayed when users click on a link but haven't been able to get it working. Actually, I'm fairly new to layer use. If sombody has come code or advice it would be greatly appriciated.

Ira
 
hi

here is an example:
cut-paste-play with it, ask if something's not working, gotta work in ie4+, nn4+, opera

~~~~~~~~~~
<html><head><title>show/hide a layer (div)</title>
<style>
<!--
#l3{
position:absolute;
left:100;
top:100;
height:100;
width:100;
bgColor:red;
layer-background-Color:red;
background-color:red;
visibility:visible;
visibility:show;
}
-->
</style>
<script>
<!--
//Netscape 4x
var NC=document.layers

function setVis(name){
var oobject
//ie 4+, may be opera, ..
if (document.all){ oobject=document.all[name].style;}
else if (NC){
oobject=document.layers[name];
}else if (document.getElementById){
{//ie5+, netscape6+, mozilla/gecko/
oobject=document.getElementById(name).style}
var v=oobject.visibility
//if it was hidden, there would be h letter first in visibility property
oobject.visibility=(v.toLowerCase().indexOf(&quot;h&quot;)==0)?(NC?&quot;show&quot;:&quot;visible&quot;):(NC?&quot;hide&quot;:&quot;hidden&quot;)
}
//-->
</script>
</head>
<body>
<form>
<input type=button value=&quot;show/hide&quot; onclick=&quot;setVis('l3')&quot;>
</form>
<div id=l3>The layer (division, if you want)</div>
</body>
</html>
~~~~~~~~~~

also check this out:
may be some others..

this is pretty interesting:
Victor
 
Thanks Victor,

I think I see how it works.

I do get some errors (an excepted '}' in line 36, I added another ). Also, I cannot get the layer to appear or disappear. I tried changing the visibility property of the style and in the script but to no avail. Basically, I want to have users click on an image or button and display a layer.

Ira
 
woops

..else if (document.getElementById){
{
//ie5+, netscape6+, mozilla
..

there shouldn't be the second (red) bracket :)
& then it works
 
Victor,

that did it. Thanks so much.

Ira
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top