Forum Moderators: open

Message Too Old, No Replies

Using Variables

         

Twister77

10:19 pm on Nov 2, 2005 (gmt 0)

10+ Year Member



Simply, I'm just trying to have mouseover effects on some various list items that when moused over, show a layer. But when you select another item, I want the previously shown layer to disapear so that the new layer can be shown.

So I made a function that sets the old layer to hidden and the newly selected layer to visible. I'm just not sure how to get the 'last_obj' variable to

A. Get into the function
B. Get out of the function so the function can use it next time a mouseover occurs.

Here is what I have now:

<script>

function unit_select(obj, last_obj) {

last_obj.style.visibility='hidden';
obj.style.visibility='visible';
last_obj = obj;

}

</script>

<html>

<a onMouseOver="unit_select(Layer1, last_obj);"></a>

</html>

Twister77

10:28 pm on Nov 2, 2005 (gmt 0)

10+ Year Member



Here is an update... hopefully making it more clear what I'm trying to do.

This is still not working.

<script>

function unit_select(obj) {

obj.style.visibility='visible';
var temp = document.vars.last_obj.value;
temp.style.visibility='hidden';
document.vars.last_obj.value=obj;
}

</script>

<form name="vars">
<div id="Layer1" style="position:absolute; visibility:hidden; background: #FFFFFF; left:84px; top:37px; width:378px; height:133px; z-index:1">
abcdef
</div>
<div id="Layer2" style="position:absolute; visibility:hidden; background: #FFFFFF; left:84px; top:37px; width:378px; height:133px; z-index:1">
zxvyt
</div>
<div id="Layer3" style="position:absolute; visibility:hidden; background: #FFFFFF; left:84px; top:37px; width:378px; height:133px; z-index:1">
mjauo
</div>

<a onMouseOver="unit_select(Layer1);">1</a>
<a onMouseOver="unit_select(Layer2);">2</a>
<a onMouseOver="unit_select(Layer3);">3</a>

<input type="hidden" name="last_obj" value="Layer1">
</form>

Bernard Marx

11:11 pm on Nov 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>TEST</title>
<style type="text/css">
.myLayer{
position:absolute; left:84px; top:37px;
width:378px; height:133px;visibility:hidden;
background: #FFFFFF; border: solid 1px #ADD8E6;
}
</style>
<script>
/*
Don't rely on ids as global variables to
reference elements. Use doc.getElementById
*/

var myLayerCurr;

function unit_select(id)
{
if(myLayerCurr)
myLayerCurr.style.visibility='hidden';
myLayerCurr = document.getElementById(id);
myLayerCurr.style.visibility='visible';
}
</script>
</head>
<body>

<div id="layer1" class="myLayer">abcdef</div>
<div id="layer2" class="myLayer">zxvyt</div>
<div id="layer3" class="myLayer">mjauo</div>

<a onmouseover="unit_select('layer1');" href="javascript:void()">1</a>
<a onmouseover="unit_select('layer2');" href="javascript:void()">2</a>
<a onmouseover="unit_select('layer3');" href="javascript:void()">3</a>

</body>
</html>

Twister77

3:00 pm on Nov 3, 2005 (gmt 0)

10+ Year Member



That works great!

Thank you