[thelist] Logic problem with a JavaScript image toggle...

Chris Marsh chris at www.ecleanuk.com
Fri Nov 7 11:05:52 CST 2003


> Thanks for your insight.
> 
> I tried the other example you give, however, beyond the initial click
> (which works), clicking again does not toggle it back.
> 
> I threw in an alert to see what path the img.src gives, and it's from
> the root - therefore, the path doesn't seem to match the relative path
> to the file specified, and I guess that means the first conditional is
> being ignored...
> 
> Is that Internet Explorer 'filling in the blanks'?
> 
> Or?
> 

Try:

function flip(imageID) {
     var img = document.getElementById(imageID);
     if (img.src.indexOf('images/menuarrow_off.gif') > -1) {
         img.src = 'images/menuarrow_on.gif'
     } else {
         img.src = 'images/menuarrow_off.gif'
     }
}

Regards

Chris Marsh



More information about the thelist mailing list