Hello,
I am having a small problem with functions in Javascript.
My task is to create 3 buttons, when one gets clicked it is switched on or off.
Rather than have SUBs for each button, I wanted to use a function.
This is the function:
function flip(FlipToImage) {
if (OnOff==’Off’)
{
document.images[FlipToImage].src = ‘Graphics/Tick.png’
OnOff=’On’;
}
else
{
document.images[FlipToImage].src = ‘Graphics/EmptyButton.png’
OnOff=’Off’;
}
}
And this is the button-code:
<a href=’#’ onClick=’flip(“Image1”);return false’><img src=’Graphics/EmptyButton.png’ name=’image1′></a>
<a href=’#’ onClick=’flip(“Image2”);return false’><img src=’Graphics/EmptyButton.png’ name=’image2′></a>
<a href=’#’ onClick=’flip(“Image3”);return false’><img src=’Graphics/EmptyButton.png’ name=’image3′></a>
So – when you click on Image1, the flip kicks in and is supposed to switch the corresponding button on or off. etc.. for image2 and image3.
The error seems to be related to the part where
document.images[FlipToImage].src
I’ve tried putting document.images[‘FlipToImage’].src but that makes no difference.
Can you not you a function variable in an object?
Thanks!
Carl.