Image swap

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpnewbie2008
Forum Newbie
Posts: 1
Joined: Sun Jan 20, 2008 11:32 am

Image swap

Post by phpnewbie2008 »

I have a <td> where the main picture is displayed and on the other td's the thubnails. Now I want to change the main picture with the thubnail picture everything a different picture is clicked.

The main picture is now showing :

<img src="viewImage.php?type=glimage&name=<?php echo $image['im_image']; ?>" border=0 id="main">

now I have tried :

<a href="#" onclick="main.src='viewImage.php?type=glimage&name=<?php echo $image['im_image2']; ?>"><img src="viewImage.php?type=glimage&name=<?php echo $image['im_image2']; ?>" alt="Click to enlarge" style="border:1px solid #000000; width:70; height:53px;">

This does not change the picture in the first td.

What am i doing wrong?

Any help would be appreciated
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Image swap

Post by Jonah Bron »

I think this is a JS question:

Code: Select all

<!-- MAIN PIC -->
<img src="some-picture.jpg" id="main_pic" />
<!-- A THUMBNAIL -->
<img src="some-other-picture.jpg" style="cursor: pointer;"onclick="document.getElementById('main_pic').src=this.src;" />
Post Reply