Solved

Multiple images and multiple hyperlinks

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

828 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