|
|
 |
Re: FN-FORUM: Javascript problem (another one!)
date posted 9th August 2003 11:50
hi nita,
everything looks fine with your code, and yes, the onClick version you
have below would work - the only thing you have missed are some
quotemarks around the name of the layer you are trying to show/hide...
so your piece of code should read:
Link 4
where the DIVs are named as such in the CSS i.e. #linkone { blah blah }
and then called in the HTML like something in
here
if you wanted to further optimise the code, you could create a variable
called 'layerFlag' each time the function is called, so that you don't
have to cycle through all the layers to turn them off each time, the
code would always know the last layer that was made visible.
this would work like this (assuming that the layer 'linkone' was
visible on loading the page, but it doesn't really matter, you just
have to set the variable up with something before using it :-)
var layerFlag = 'linkone';
function swapIt(thisone) {
if (thisone == layerFlag) return;
document.all[layerFlag].style.visibility = 'hidden';
document.all[thisone].style.visibility = 'visible';
layerFlag = thisone;
}
and then in your HTML you would simply need:
Link 4
i have added the line: if (thisone == layerFlag)... this just quits
the user from the function if they happen to click a link to a layer
that is already visible, so that they don't see a flash as the same
layer disappears and reappears again!
HTH!
luke
On Friday, August 8, 2003, at 09:04 PM, Nita wrote:
> Hi Luke, I was trying out the script you sent and I'm not sure if I'm
> using
> it properly...
>
>
> I've put the function in and I have the following mouseovers and outs:
>
>
> onMouseout="swapOut(textrhs);
> ">Introduction
> onMouseout="swapOut(linkone);
> ">How does this on-line course work?
> onMouseout="swapOut(linktwo);">Registration Form
> onMouseout="swapOut(linkthree);">Study Plan
> onMouseout="swapOut(linkfour)">Link 4
>
> Each time I hover I get:
>
> document.all[...].style is null or not an object
>
> I'm afraid I can't see where I'm making a mistake....
>
> Also, I wanted to show the divs onClick - I was getting the same error
> and
> being diverted to my folder and it was bugging me so I changed it for
> ease
> of testing! But it also occured to me that I would need to swapout
> each div
> something like this:
>
> swapOut(linktwo);
> swapOut(linkone);">Link 4
>
> Would this make sense? I couldn't tell if it would have worked
> because I
> was getting the same error as above....
>
> Can you shed any light on it?
>
> Very much appreciated if you can!
>
> Nita
> ;o)
|
 |
|