View Full Version : Javascript Issue (swapping image)

03-15-2009, 08:30 PM
Hello. I am having a bit of a difficult time here with this javascript I have. It works perfectly for what I want it to do, which is switch the big image with the thumbnails, but I need the big image to change links on switch, so when you click on the big image it takes you to the full size of the preview. Here is the site I am working on:


If you look to the right, you will see a featured wallpaper section where it offers a big image (the preview image) and below it, 5 thumbnails. Those thumbnails work to switch them out with the big image, which is perfect. The problem is when they switch, the link of the preview image stays the same, therefore not linking them to the correct full size image. Here is the code:

<div id="wallpapers">
<center><a href="http://img14.imageshack.us/img14/9200/tiwall.jpg" name="wallpaper_url"><img src="./images/FeaturedWALL.png" name="img13" border="0" alt="Featured Wallpaper"></a></center>
<div class="thumb"><a href="#" onClick="javascript:wallpaper_url.href='www.mynewsite.com';"><img src="./images/Wallthumb1.png" name="img18" border="0" alt="#2" onClick="javascript:img13.src='./images/FeaturedWALL.png';return false;"></a></div><div class="thumb"><a href="#" onClick="javascript:wallpaper_url.href='www.mynewsite.com';"><img src="./images/Wallthumb2.png" name="img19" border="0" alt="#2" onClick="javascript:img13.src='./walls/2.png';return false;"></a></div><div class="thumb"><a href="#" onClick="javascript:wallpaper_url.href='www.mynewsite.com';"><img src="./images/Wallthumb3.png" name="img16" border="0" alt="#2" onClick="javascript:img13.src='./walls/5.png';return false;"></a></div><div class="thumb"><a href="#" onClick="javascript:wallpaper_url.href='www.mynewsite.com';"><img src="./images/Wallthumb4.png" name="img17" border="0" alt="#2" onClick="javascript:img13.src='./walls/3.png';return false;"></a></div><div class="thumb2"><a href="#" onClick="javascript:wallpaper_url.href='www.mynewsite.com';"><img src="./images/Wallthumb5.png" name="img18" border="0" alt="#2" onClick="javascript:img13.src='./walls/4.png';return false;"></a></div>


Any help would be appreciated. Thanks!

03-16-2009, 01:05 PM
I would suggest replacing the 'name' attribute in your large images' anchor tag with an 'id' attribute. 'name' is used for constructing links to a specific part of a page - 'id' is used by the DOM to uniquely identify a specific element.

03-16-2009, 11:02 PM
Java is very different from JavaScript. I've moved this thread to the later forum category.

Old Pedant
03-16-2009, 11:23 PM
WA: How do you want/prefer that people report posts in wrong forum to you? Or would you rather not get inundated?