Solved

Changing IMG SRC onclick (need to extend functionality)

Posted on 2008-06-20
2
673 Views
Last Modified: 2011-09-20
http://208.106.137.37/gallery.php?cat=9&ID=94

If you take a look at this example (See link above) -- I already have some functionality in place to change out the IMG SRC attribute of the large image when you click on the smaller thumbnail images.  

I need to somehow take this one step further.  More specifically, ... I also need to change out the IMG SRC attributes of the thumbnail images that are clicked.

In my application, a product can have up to 3 images associated with it -- the main image (the large one that's displayed by default) .. and up to 2 additional images (initially represented by thumbnail images).  

A small thumbnail image is created for each of these product images that are uploaded (including the main one) .. and I recently realized that there is currently no way to display the default image again after one of the thumbnail images has been clicked, .. unless the page is refreshed.  

What I'd like to have happen is ... when you click on one of the thumbnail images, .. the IMG SRC attribute of the thumbnail image that was just clicked would be changed to the thumbnail image representing whichever of the large product images was just previously displayed on the left -- in addition to changing out the IMG SRC attribute of the large image (this is how it's currently functioning).

Here's a more visual description of what we'd like to achieve
(upper case = large image & lower case = thumbnail image):

IMAGE1 .. image2   image3

click on image2 = IMAGE2 .. image1   image3

click on image3 = IMAGE3 .. image1   image2

click on image1 = IMAGE1 .. image3   image2


So basically, .. if there are a total of 3 image associated with a product, each of those 3 product images should always be visable/clickable on the page, .. as either a large image or a thumbnail image.

How might I accomplish this using javascript?  Is it even possible?

Thanks in advance,
- Yvan
0
Comment
Question by:IDEASDesign
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 21830959
Hello IDEASDesign,

onclick="var bp=document.getElementById('bigPhoto').src;var tp=this.src.replace('tn2_','');document.getElementById('bigPhoto').src=tp;this.src=bp.replace('products/','products/tn2_');"

Change the onclick of the thumbnails to this and it will do what you need.

Regards,

TimCottee
0
 

Author Comment

by:IDEASDesign
ID: 21831923
Ahh .. awesome!  Thanks so much!  That works great!

- Yvan
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Jquery form 9 64
Link Anchor Not working 9 67
Problem in javascript 17 56
Submit button if clicked twice submits twice 1 24
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question