how to load a different image on a web page and attach a hyperlink

This is a discussion on "how to load a different image on a web page and attach a hyperlink" within the JavaScript Forum section. This forum, and the thread "how to load a different image on a web page and attach a hyperlink are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Mar 30th, 2007, 18:54
New Member
Join Date: Mar 2007
Location: Boston
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Question how to load a different image on a web page and attach a hyperlink

Hello,
I am looking for code that will load different image on a web page and attach a hyperlink to each picture and if possible have a read artilce link associated with the image.

I did find some code that let me load the images but i can not associate a link with it.
Code: Select all
var urls="http://www.apem.com/news/" ;
var a=[
['Joy_gr-jaune_ico.jpg',170,170,'Industrial Joysticks'],
['Serie-IA_icone.jpg',181,198,'Pushbutton Switches'],
['ACF6573.jpg',170,170,'Boots for Pushbutton Switches'],
['',,,''],
['',,,''],
['',,,''],
['',,,'']
] 

for(i=0;i<a.length;i++){a[i][0]=urls+a[i][0]};

var cflip=Math.round((a.length-1)*Math.random()) ;
document.write('<p class="h"><img src="'+a[cflip][0]+'" width="'+a[cflip][1]+'" height="'+a[cflip][2]+'" alt="'+a[cflip][3]+'"><br>'+a[cflip][3]+'<\/p>');

Last edited by karinne; Mar 30th, 2007 at 19:22. Reason: Please use [code]...[/code] tags when displaying code!
Reply With Quote

  #2 (permalink)  
Old Apr 1st, 2007, 14:53
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,619
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: how to load a different image on a web page and attach a hyperlink

add link tags around the code....
Code: Select all
document.write('<p class="h"><a href="URL.htm"><img src="'+a[cflip][0]+'" width="'+a[cflip][1]+'" height="'+a[cflip][2]+'" alt="'+a[cflip][3]+'"><br>'+a[cflip][3]+'<\/a><\/p>');
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Reply With Quote
  #3 (permalink)  
Old Apr 2nd, 2007, 15:30
New Member
Join Date: Mar 2007
Location: Boston
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Re: how to load a different image on a web page and attach a hyperlink

Thank you

when i click on the picture it want's to go to url.htm how do i customize the line
['Joy_gr-jaune_ico.jpg',170,170,'Industrial Joysticks', url='joystick_news.html'],

looking foward to your reply
Reply With Quote
  #4 (permalink)  
Old Apr 2nd, 2007, 15:48
New Member
Join Date: Mar 2007
Location: Boston
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Re: how to load a different image on a web page and attach a hyperlink

Spinal007,
I figured it out, never would of got without you

Thank you
Reply With Quote
  #5 (permalink)  
Old Apr 2nd, 2007, 16:52
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,619
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: how to load a different image on a web page and attach a hyperlink

No problem and well done for trying and getting there! I hope you stick around and enjoy Webforumz...

I'll post my reply anyway because this might help somebody who comes across this post in the future.

This is an array...
['Joy_gr-jaune_ico.jpg',170,170,'Industrial Joysticks']

You went wrong by putting url= in the array...
['Joy_gr-jaune_ico.jpg',170,170,'Industrial Joysticks', url= 'NEW 1'] // ERROR

Add items to an array like this...
['Joy_gr-jaune_ico.jpg',170,170,'Industrial Joysticks', 'NEW 1', 'NEW 2']

In your case, the index of 'NEW 1' is 4 (as it's the 5th item of the array).
So you can access it using [4].

Which in your case, would be:
document.write('<p class="h"><a href="'+a[cflip][4]+'
">
<img src="'+a[cflip][0]+'" width="'+a[cflip][1]+'" height="'+a[cflip][2]+'" alt="'+a[cflip][3]+'"><br>'+a[cflip][3]+'<\/a><\/p>');
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Reply With Quote
Reply

Tags
different, hyperlinks, images, web papes

Thread Tools

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
Page Load Issue kathyc JavaScript Forum 1 Jun 13th, 2008 02:21
Load part of a page. magiccupcake Web Page Design 8 Jun 23rd, 2007 11:44
How to use a javascript variable to load an image VanderBOOM JavaScript Forum 2 Nov 13th, 2006 14:00
A hyperlink that passes a variable to a page oz_egirl Classic ASP 1 Jan 18th, 2006 16:23
image as hyperlink question bklcomputing Web Page Design 2 May 20th, 2005 06:56


All times are GMT. The time now is 22:43.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43