Jump to content

Change one image by clicking another


nd3_2000

Recommended Posts

hi guys, I have looked over Google for this and cant seem to find what I need atall!

 

Basically I have a webpage with small thumbs at the bottom and a main image at the top, I would like to change the main image on the page when I click on any of the thumbnails.........

 

Does anybody have a function they can provide me with or giudance for this as I thought this wqould be easy to find but its not apparantly

 

Cheers

Neil

Link to comment
https://forums.phpfreaks.com/topic/189084-change-one-image-by-clicking-another/
Share on other sites

if you want to fire the event  on your thumbs set this attribute, to each one :

 

<image src=".." onclick="changeMainImage('put here the path of you main image');" >

then you can put this function on a script tag:

<script type="text/javascript">
    function changeMainImage(url)
    {
          /*now here you have to get the element of you main top image, supposing that you are usins as an id "myMainImage" ok!
           */
          var mainImage = document.getElementById('myMainImage');
          // here we are setting to the maing image the path you receive as a param
           mainImage.src = url;
    }
</script>

 

and i think that's all :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.