Solved

Multiple images and multiple hyperlinks

Posted on 2006-10-25
2
557 Views
Last Modified: 2012-05-05
Hi,

I have this code... The images change randomly on page refresh - Can someone help me make the hyperlink change everytime the page refreshes along with the picture - i.e. i want a pic to a url - now its 5 pics to one url


<a href = "http://www.site.com/" target = _blank>
<SCRIPT LANGUAGE="Javascript"><!--


function image() {
};

image = new image();
number = 0;

// imageArray
image[number++] = "<img src='images/birthday0.jpg' border='0'>"
image[number++] = "<img src='images/birthday1.jpg' border='0'>"
image[number++] = "<img src='images/birthday2.jpg' border='0'>"
image[number++] = "<img src='images/birthday3.jpg' border='0'>"
image[number++] = "<img src='images/birthday4.jpg' border='0'>"


increment = Math.floor(Math.random() * number);

document.write(image[increment]);

//--></SCRIPT></a>


Thanks
0
Comment
Question by:mrperfect75000
  • 2
2 Comments
 
LVL 4

Expert Comment

by:anilande
ID: 17809208
here is the solution



<SCRIPT LANGUAGE="Javascript">

var anchor = new Array();
number = 0;

// imageArray
anchor[number++] = "<a href = 'http://www.site0.com/' target = _blank><img src='images/birthday0.jpg' border='0'></a>";
anchor[number++] = "<a href = 'http://www.site1.com/' target = _blank><img src='images/birthday1.jpg' border='0'></a>";
anchor[number++] = "<a href = 'http://www.site2.com/' target = _blank><img src='images/birthday2.jpg' border='0'></a>";
anchor[number++] = "<a href = 'http://www.site3.com/' target = _blank><img src='images/birthday3.jpg' border='0'></a>";
anchor[number++] = "<a href = 'http://www.site4.com/' target = _blank><img src='images/birthday4.jpg' border='0'></a>";


increment = Math.floor(Math.random() * number);

document.write(anchor[increment]);
</SCRIPT>
0
 
LVL 4

Accepted Solution

by:
anilande earned 500 total points
ID: 17809217
or u can use this too

<a href = "http://www.site.com/" target = _blank id='imglink'>
<SCRIPT LANGUAGE="Javascript">
var image = new Array();
var url = new Array();
var number = 0;
function addimage(imgsrc,link)
{
      image[number] = "<img src='images/"+imgsrc+"' border='0'>";
      url[number]=link;
      number++;
}



// imageArray
addimage("birthday0.jpg","http://www.link1.com");
addimage("birthday1.jpg","http://www.link2.com");
addimage("birthday2.jpg","http://www.link3.com");
addimage("birthday3.jpg","http://www.link4.com");
addimage("birthday4.jpg","http://www.link5.com");

increment = Math.floor(Math.random() * number);

document.write(image[increment]);
document.getElementById('imglink').href=url[increment];
</SCRIPT></a>
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now