Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looking for a way to swap images with captions using .jpg & .txt files

Status
Not open for further replies.

Chiron

Programmer
May 11, 2001
1
US
Hello,

I am working on a project to showcase jewelry on a web page. I have divided the page into two columns, with a large image on the left, and several thumbnails on the right side. When the user clicks on one of the thumbnails, the large picture is replaced with the one that matches the thumbnail. The code so far is as follows:

<a href=&quot;#&quot; onClick=&quot;document.image1.src='<img src=&quot;600003.jpg&quot; width=&quot;64&quot; height=&quot;64&quot;></a>

(on each thumbnail)

and:

<img src=&quot; name= &quot;image1&quot;>

(for the large image)

I would like to add a bit of code to the end of my onClick statements that would call a .txt or .htm file (or even a string in the page- I'm not too picky) and document it under the large image at the same time the large image is swapped- does anyone have any advice? Please be specific, as I am relatively new to javaScript!

Thank you,

Chiron
 
So you want to update some text as well as the bigger image right? Are your images preloaded in an array? If so just make another array with the strings corresponding to the image:

images[0].src = &quot;image_0.gif&quot;;
textForImages[0] = &quot;This is for img_0&quot;;

Then just add a piece to the end of the onClick, (or better still wrap it all up ina function) which inserts the new text in some element under the image.Unfortunately, after the page has loaded, there is no way to read from an external file, and insert HTML. If you were having a lot of ext though, you could use an iframe to display it, which means you can insert a whole new page, without refreshing.
I reckon though, you want to write a function which handles the image swapping - just to make it easier to update and read. By storing relevant things in arrays- and keeping the indices common, you can access the data pertaining to each item very easily, and add new ones very quickly.
also href=&quot;javascript:void(0)&quot; - doesn't jump when clicked.
b2 - benbiddington@surf4nix.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top