Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
Old 06-16-2009, 11:50 AM   #1 (permalink)
Contributing Member
 
Jason's Avatar
 
Join Date: 05-17-04
Location: London, United Kingdom
Posts: 710
iTrader: 0 / 0%
Latest Blog:
None

Jason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of light
Send a message via MSN to Jason
Simple JavaScript help please - image embedding

Hi all, I hope this finds you all well!

I have a website that will need to handle about 20+ images per page, but for the sake of a clean layout I want them arranged so the user scrolls through a couple of tiny galleries instead of being presented with a long stream and having work their way through.

Code:
<script> function changeImage(filename) { document.mainimage.src = filename; } </script> <p align="center"> <img name="mainimage" src="DSCF2715.JPG"></p> <p align="center">Images: <a href="javascript:changeImage('DSCF2715.JPG')">1</a> <a href="javascript:changeImage('DSCF0605.JPG')">2</a> <a href="javascript:changeImage('image3.jpg')">3</a> <a href="javascript:changeImage('image4.jpg')">4</a> <a href="javascript:changeImage('image5.jpg')">5</a></p>
That said, I've found an image click-through gallery script here... but it only seems to work once per page; any more times and those below the top click-through fail to work. How can this be manipulated in a way to be used several times loading different, pre-defined images?

ONLINE DEMONSTRATION: http://i-code.co.uk/javascript/imageviewer.php

Your help on this matter will be greatly appreciated!

Take care,

Jason

Last edited by Jason; 06-16-2009 at 11:56 AM..
Jason is offline  
Add Post to del.icio.us
Reply With Quote
Old 06-16-2009, 12:52 PM   #2 (permalink)
Meeow!
 
Costin Trifan's Avatar
 
Join Date: 04-13-07
Location: Romania
Posts: 3,235
iTrader: 0 / 0%
Latest Blog:
None

Costin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest order
you need to change the target, so your function would become:
Code:
function changeImage(filename, target) { document.target.src = filename; }
and in your file:
Code:
<p align="center"> <img name="mainimage" src="DSCF2715.JPG"></p> <p align="center">Images: <a href="javascript:changeImage('DSCF2715.JPG', 'mainimage')">1</a> <a href="javascript:changeImage('DSCF0605.JPG', 'mainimage')">2</a> <a href="javascript:changeImage('image3.jpg', 'mainimage')">3</a> <a href="javascript:changeImage('image4.jpg', 'mainimage')">4</a> <a href="javascript:changeImage('image5.jpg', 'mainimage')">5</a></p> <p align="center"> <img name="mainimage2" src="DSCF2715.JPG"></p> <p align="center">Images: <a href="javascript:changeImage('DSCF2715.JPG', 'mainimage2')">1</a> <a href="javascript:changeImage('DSCF0605.JPG', 'mainimage2')">2</a> <a href="javascript:changeImage('image3.jpg', 'mainimage2')">3</a> <a href="javascript:changeImage('image4.jpg', 'mainimage2')">4</a> <a href="javascript:changeImage('image5.jpg', 'mainimage2')">5</a></p>
I think this should do it
__________________
...to be continued
Costin Trifan is offline  
Add Post to del.icio.us
Reply With Quote
Old 06-16-2009, 01:20 PM   #3 (permalink)
Contributing Member
 
Jason's Avatar
 
Join Date: 05-17-04
Location: London, United Kingdom
Posts: 710
iTrader: 0 / 0%
Latest Blog:
None

Jason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of light
Send a message via MSN to Jason
Hi Costin,

Thanks for your help.

I've just re-tried, but it won't load any images. I'm confident it will work, it just needs someone like yourself who has more knowledge of coding! Yes, I'm sure the Target thing is the problem.

The whole page now looks like this:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <script></script> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> <title>hh</title> </head> <body> <script> function changeImage(filename, target) { document.target.src = filename; } </script><br> - <p align="center"> <img name="mainimage" src="Beetle6.JPG"></p> <p align="center">Images: <a href="javascript:changeImage('Beetle6.JPG', 'mainimage')">1</a> <a href="javascript:changeImage('Cardinal.jpg', 'mainimage')">2</a> <a href="javascript:changeImage('image3.jpg', 'mainimage')">3</a> <a href="javascript:changeImage('image4.jpg', 'mainimage')">4</a> <a href="javascript:changeImage('image5.jpg', 'mainimage')">5</a></p> <p align="center"> <img name="mainimage2" src="16-sp.jpg"></p> <p align="center">Images: <a href="javascript:changeImage('24-sp.jpg', 'mainimage2')">1</a> <a href="javascript:changeImage('16-sp.jpg', 'mainimage2')">2</a> <a href="javascript:changeImage('image3.jpg', 'mainimage2')">3</a> <a href="javascript:changeImage('image4.jpg', 'mainimage2')">4</a> <a href="javascript:changeImage('image5.jpg', 'mainimage2')">5</a></p> </body> </html>

Thanks for helping!

Last edited by Jason; 06-16-2009 at 01:23 PM..
Jason is offline  
Add Post to del.icio.us
Reply With Quote
Old 06-16-2009, 02:47 PM   #4 (permalink)
Contributing Member
 
Jason's Avatar
 
Join Date: 05-17-04
Location: London, United Kingdom
Posts: 710
iTrader: 0 / 0%
Latest Blog:
None

Jason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of lightJason is a glorious beacon of light
Send a message via MSN to Jason
Hi,

Since reading your helpful post about targets, etc., I found another script that does the same thing. It too failed when used twice on the same page, so as you said I re-numbered the target - and SUCCEEDED!!!!!

I'm greatful for your assistance - please either post or PM me your website address you'd like used alongside a name-check so I can credit you when the site goes live.

Thanks.

EDIT: We cross-posted! I posted my alternative before I saw your assistance. The offer of credit, naturallly, still stands.
Jason is offline  
Add Post to del.icio.us
Reply With Quote
Old 06-16-2009, 02:44 PM   #5 (permalink)
Meeow!
 
Costin Trifan's Avatar
 
Join Date: 04-13-07
Location: Romania
Posts: 3,235
iTrader: 0 / 0%
Latest Blog:
None

Costin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest order
The document.target.src throws an error. I didn't test it, I've just updated the code here, but now that I've tested on my machine, it works; so here's what you need to change in your code:

#1: give an ID to each image placeholder. you can use the name for the ID too ( so it will look like this: <img name="mainimage" id="mainimage" src="1.gif">)

#2 change the function to this:

Code:
<script type="text/javascript"> function changeImage(filename, target) { //document.target.src = filename; document.getElementById(target).src = filename; } </script>
__________________
...to be continued
Costin Trifan is offline  
Add Post to del.icio.us
Reply With Quote
Old 06-16-2009, 02:55 PM   #6 (permalink)
Meeow!
 
Costin Trifan's Avatar
 
Join Date: 04-13-07
Location: Romania
Posts: 3,235
iTrader: 0 / 0%
Latest Blog:
None

Costin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest order
it was my pleasure, no need for any credits at all but thank your for the offer
__________________
...to be continued
Costin Trifan is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting 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


Similar Threads
Thread Thread Starter Forum Replies Last Post
simple javascript troubleshoot chuco61 Coding Forum 14 08-08-2008 12:25 PM
Embedding Quicktime video with an image capture Gr8Writer Coding Forum 1 07-09-2007 08:10 PM
Simple javascript solution??? searchbliss Coding Forum 5 06-27-2007 04:52 PM
JS: Simple Javascript But please help Calisonder Coding Forum 1 04-17-2007 08:48 PM
Simple JavaScript question I, Brian Coding Forum 16 01-07-2005 11:27 AM


Sponsor Links
Get exposure! Contextual Links V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 10:21 AM.
© Copyright 2008 V7 Inc
Powered by vBulletin
Copyright © 2000-2009 Jelsoft Enterprises Limited.


Search Engine Optimization by vBSEO 3.3.0 ©2009, Crawlability, Inc.