PDA

View Full Version : onClick event handler


rockshox
10-27-2002, 03:20 PM
Greetings, Trying to get the onClick event handler to work for the showlayer and hideLayer functions. Do not like the idea of using the DblClick event handler to hide the layer because it is somewhat awkward, but not having any luck. Thanks.



<a href="#" onClick="showLayer('home');"
onDblClick="hideLayer('home');">Home</a>

mordred
10-27-2002, 03:39 PM
Excuse me, but where's your specific question? All I get from your post is that something does not work as intended, but that's really it.

Anyway, I *think* it might come from the fact that you don't stop the propagation of the click event.

<a href="#" onClick="showLayer('home'); return false;"
onDblClick="hideLayer('home'); return false;">Home</a>

Mr J
10-27-2002, 04:13 PM
Try going in this direction, but the problem is that it can only work with one layer ...... for now ....


<script language="javascript">
<!--
Count=0
timer=""

function Set_Count(layer){
Count++ // increase Count value by 1

if(Count==1){
showlayer(layer)
}
else{
hidelayer(layer)
Count=0 // reset Count value
}
}

function showlayer(layer){
alert("Show Layer "+layer)
}

function hidelayer(layer){
alert("Hide Layer "+layer)
}
// -->
</script>

<a href="#null" onclick="Set_Count('home')">Home</a>

rockshox
10-27-2002, 05:07 PM
Sorry for any confusion with the question. Do more work with Flash and ColdFusion. Here are the functions:
// Function to show a menu
function showLayer(layerid) {
var layer = document.getElementById(layerid);
layer.style.visibility = "visible";
}

// Function to hide a menu
function hideLayer(layerid) {
var layer = document.getElementById(layerid);
layer.style.visibility = "hidden";
}

I want to single click to show layer and single click to hide layer. When I do this:
<a href="#" onClick="showLayer('homeLayer');"
onClick="hideLayer('homeLayer');">Home</a>
I get an error in Dreamweaver saying invalid because it contains a duplicate attribute. Hope this helps.

Terry
10-27-2002, 05:27 PM
Try something like this:


function showHide(layerid)
{
if (document.getElementById(layerid).style.visibility != "hidden")
{
document.getElementById(layerid).style.visibility = "hidden";

}
else
{
document.getElementById(layerid).style.visibility = "visible";
}
}

<a href="#" onClick="showLayer('home');">Home</a>

rockshox
10-27-2002, 06:00 PM
Thanks for your reply.
I an getting an error. I think it is coming from: visibility:hidden
Do I need to change this?

<div id="homeLayer"
style="position:absolute; left:110px; top:23px;
width:100px; height:62px; z-index:1;
background-color:#CCCCCC; layer-background-color:#CCCCCC; visibility:hidden">

rockshox
10-27-2002, 06:54 PM
Thanks Terry that worked. The error was coming from some place else. You changed the function name so I needed to implement that change into the event handler.

Terry
10-27-2002, 09:15 PM
Ooops, sorry about the function name change. Glad it worked though.