Solved

Multiple images and multiple hyperlinks

Posted on 2006-10-25
2
561 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

832 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