"LAshooter" <lashooter@hotmail.com> writes:
[color=blue]
> I have a portfolio page which loads a dozen thumbnails and one large image.
> A friend helped me code a script (below) which will swap out the large image
> (named "imgLarg") when a different thumbnail is clicked. Both the thumbnail
> and the enlargement are identically named, one is in /thumbs/ and one is in
> /enlargements/ - tricky, huh? ;-)[/color]
Not particularly. Your code suggests that the directories are actually
"thumbs" and "images". Which is it? I'll assume "enlargements" for now.
[color=blue]
> What's the easiest way to make this work in other browsers as well?[/color]
Rewrite from scratch. The script assumes that it runs in IE, and does
things that only work in the browser.
[color=blue]
> <script language="JavaScript">[/color]
For completeness, this is better (more standard compliant and works
just as well) written as:
<script type="text/javascript">
[color=blue]
> function enlarge() {[/color]
When you want to work on the element that was clicked, the easiest
way to do that is to receive the element as an argument. It is
easy to provide, since it is available in the onclick event handler:
<img src="../thumbs/..." onclick="enlarge(this);">
Then receive it as:
function enlarge(thumbImage) {
[color=blue]
> oSrcElem = event.srcElement;[/color]
That makes this IE'ism unnecessary.
[color=blue]
> imgLarge.src = oSrcElem.src.replace(/thumbs/,'images');[/color]
Here you need to get a reference to the image element with name
"imgLarge". That is best done through the images collection:
document.images['imgLarge']
The assignment looks fine, as long as you are sure "thumbs" cannot
occour elsewhere in the string, previous to the instance to replace.
So:
document.images['imgLarge'].src =
thumbImage.src.replace(/thumbs/,"enlargements");
[color=blue]
> }
> </script>[/color]
Good luck
/L
--
Lasse Reichstein Nielsen -
lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'