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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

still have layer problems

Status
Not open for further replies.

ironyx

Technical User
Nov 13, 2001
134
0
0
US
Have five layers that are fixed to buttons the user clicks to change layers. I use a function which uses an "if (value == number){ show layer1}
The only problem is on loading the page all layers are hidden. Then, if I have layer1 as default with body onload, every time you switch pages that particular layer pops up until you hit one of the buttons. Does anyone know if I could do a function for body onLoad that checks to see if a layer is visible and/or the button has been clicked and then passes the variable into the body onLoad?

function changeLayer(){
if(document.DocLocation.visibility="show")
{showOrHide(0);}
else if(document.DocPoc.visibility="show")
{showOrHide(1);}
else if(document.DocComponent.visibility="show")
{showOrHide(2);}
else if(document.DocSoftware.visibility="show")
{showOrHide(3);}
else if(document.DocSwitch.visibility="show")
{showOrHide(4);}
}
//-->

</SCRIPT>
</head>
<body onLoad=&quot;showOrHide();&quot; onUnload=&quot;changeLayer();&quot; >

This still only shows layer one. I have to script for netscape browsers too. Any ideas?
Thanks!
Va :)
 
// dont u mean ...

function changeLayer(){
if(document.DocLocation.visibility=&quot;show&quot;) {showOrHide(0);}
if(document.DocPoc.visibility=&quot;show&quot;) {showOrHide(1);}
if(document.DocComponent.visibility=&quot;show&quot;) {showOrHide(2);}
if(document.DocSoftware.visibility=&quot;show&quot;) {showOrHide(3);}
if(document.DocSwitch.visibility=&quot;show&quot;) {showOrHide(4);}
}
---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
Does [tt]showOrHide()[/tt] also hide the visible layers and/or reset the z-indexes? Paul Ellis
[hammer] I've been programming since you had to punch holes in cards to code. (Always remember, number your cards!)
 
I do hide the other layers.

function showOrHide(value)
if ==0
show layer1
hide layer2
hide layer3

so, yes. And with the 'if' statements it was doing strange things so I tried the 'else if' but that wasn't exactly the way to go...obviously ;)
So, whaddya think? Should I be accounting for something else maybe?
Thanks for checking on me!!!
Va.
 
It seems to me that you're going to need to cookie whatever value you want, then set a global variable to the cookied value or if the cookie doesn't exist, set it to the default value. Set the cookie to expire in one hour (or some other similarily short time value), so you don't run into the a problem with revisits to your page. The pseudo code works out to something like this:
[ul][li]Page begins to load[/li]
[li]In [tt]<HEAD>[/tt] script declares variable for layer value (ie [tt]var layerToShow=0;[/tt]) and checks for cookie[/li]
[li]If cookie exists, the set [tt]layerToShow[/tt] equal to the cookie value[/li]
[li][tt]<BODY>[/tt] loads, invoking [tt]showOrHide()[/tt][/li]
[li](see [tt]showOrHide()[/tt] and [tt]changeLayer()[/tt] functions below)[/li]
[li]Things happen (I really like this part! [wink])[/li]
[li][tt]<BODY>[/tt] unloads and invokes a function to set the cookie to the [tt]layerToShow[/tt] value[/li]
[li]Another page loads, etc...[/li][/ul]
I don't know what logic you're using here, so the below is what I interpreted from your sample code. You'll probably want to rework the specifics.
[tt]
function changeLayer(){
if(document.DocLocation.visibility='show'){showOrHide(0);return;}
if(document.DocPoc.visibility='show'){showOrHide(1);return;}
if(document.DocComponent.visibility='show'){showOrHide(2);return;}
if(document.DocSoftware.visibility='show'){showOrHide(3);return;}
if(document.DocSwitch.visibility='show'){showOrHide(4);return;}
}

function showOrHide(value){
if(isNaN(value)){value=layerToShow;)
document.DocLocation.visibility='hidden';
document.DocPoc.visibility='hidden';
document.DocComponent.visibility='hidden';
document.DocSoftware.visibility='hidden';
document.DocSwitch.visibility='hidden';
switch(value){
case 0:
document.DocPoc.visibility='show';
break;
case 1:
document.DocComponent.visibility='show';
break;
case 2:
document.DocSoftware.visibility='show';
break;
case 3:
document.DocSwitch.visibility='show';
break;
default:
document.DocLocation.visibility='show';
}
}
[/tt]
I don't know if this helps any, but here it is! [noevil]
Paul Ellis
[hammer] I've been programming since you had to punch holes in cards to code. (Always remember, number your cards!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top