Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Multiple images and multiple hyperlinks

Posted on 2006-10-25
2
Medium Priority
?
569 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Suggested Courses

916 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