Solved

Multiple images and multiple hyperlinks

Posted on 2006-10-25
2
565 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

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…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

752 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