Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Dumb Javascript Question 2

Dumb Javascript Question 2
Thread Tools
Mac Elite
Join Date: Apr 2001
Location: Frickersville
Status: Offline
Reply With Quote
Nov 22, 2005, 10:40 AM
 
i have a blog on blogspot where i would like to post a lot of images. however, the images just trail down the page one after another. i'd like to implement some kind of image viewer. here is some javascript i found:

Code:
<script> function changeImage(filename) { document.mainimage.src = filename; } </script> <p align="center"> <a href="javascript:changeImage('image1.jpg')">Image 1</a> <a href="javascript:changeImage('image2.jpg')">Image 2</a> </p>
so, that's cool. but, if i post pictures for another day (i.e. another instance of the p text), only the last one on the page will update. is there some way to implement another variable in the changeImage javascript so that it will know which p to update? also, i'd like to add comment text under the pics too. how can i have the script update some text below the image as well?

as anyone could probably tell, i'm a total newbie at this stuff, so thanks for any help.

Mystical, magical, amazing! | Part 2 | The spread of Christianity is our goal. -Railroader
     
Fresh-Faced Recruit
Join Date: Apr 2005
Location: Mpls, MN
Status: Offline
Reply With Quote
Nov 23, 2005, 04:29 PM
 
In order for you to use this with multiple images you are going to have to add an id attribute to every main image you are adding and pass that into the function.

Here's some sudo blog code.
Code:
<p>Blog Entry 1</p> <img src="image.jpg" id="image_1" /> <p align="center"> <a href="javascript:changeImage('image1.jpg', 'image_1')">Image 1</a> <a href="javascript:changeImage('image2.jpg', 'image_1')">Image 2</a> </p> <p>Blog Entry 2</p> <img src="image.jpg" id="image_2" /> <p align="center"> <a href="javascript:changeImage('image1.jpg', 'image_2')">Image 1</a> <a href="javascript:changeImage('image2.jpg', 'image_2')">Image 2</a> </p>
Here's the function code.
Code:
<script> function changeImage(filename, id) { var img = document.getElementById(id); img.src = filename; } </script>
I'm not sure if you can add the ids using blogspot. Let me know how it works.

Thus, creating the most ginormous can of whoop ass the world as ever seen.
     
forkies  (op)
Mac Elite
Join Date: Apr 2001
Location: Frickersville
Status: Offline
Reply With Quote
Dec 12, 2005, 08:39 AM
 
omg, you sir a a ****ing genius! i just implemented the changes, & they worked! thank you so much.

i have another question. could i add a line of text below the image area, then have it change as different images are clicked. in effect, i want to add updating captions. maybe add another tag to the links that would be passed to the img?

also, could i add some code to make "next" and "previous" links instead of having a ton of links?

Mystical, magical, amazing! | Part 2 | The spread of Christianity is our goal. -Railroader
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:43 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2