?
Solved

Random images on page load - Both Javascript & html required...

Posted on 2006-07-07
3
Medium Priority
?
206 Views
Last Modified: 2010-04-06
Hello, this is a question that's been asked many times before but in fragments due to people usually knowing how to get started...  Can we assume NO knowledge on my part as to how to do this? Okay, here goes:

How do I get images to display randomly on a page each time it reloads?
i.e. A page banner that is different each time it is visited.  (I don't want the image to change whilst actually on screen).

I know I need a combination of Javascript and HTML but that's all I know.  Could somebody supply all the necessary code and end this question forever?

Many thanks indeed.
0
Comment
Question by:ml1n4
[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
3 Comments
 
LVL 1

Expert Comment

by:sushestvo
ID: 17061060
<html>
 <body bgcolor="#EDEDED" text="#000000" link="#000000">
 <center>

<Script Language ="JavaScript">
 function RandomNumber()
 {
   var today = new Date();
   var num= Math.abs(Math.sin(today.getTime()/1000));
   return num;
 }
  function RandomGraphics()
 {
   var x = RandomNumber();
    if (x > .77)
 {document.write("<A HREF='http://www.womir.com/'><img src='004.jpg' align=center hspace=10></a>"); return;
 }
   if (x > .66)
 {document.write("<A HREF='http://www.womir.com/'><img src='005.jpg' align=center hspace=10></a>"); return;
 }
   if (x > .55)
 {document.write("<A HREF='http://www.womir.com/'><img src='006.jpg' align=center hspace=10></a>"); return;
 }
   if (x > .44)
 {document.write("<A HREF='http://www.womir.com/'><img src='007.jpg' align=center hspace=10></a>"); return;
 }
   if (x > .33)
 {document.write("<A HREF='http://www.womir.com/'><img src='008.jpg' align=center hspace=10></a>"); return;
 }
   if (x > .22)
 {document.write("<A HREF='http://www.womir.com/'><img src='005.jpg' align=center hspace=10></a>"); return;
 }
   if (x > .11)
 {document.write("<A HREF='http://www.womir.com/'><img src='004.jpg' align=center hspace=10></a>"); return;
 }
   if (x > 0)  
 {document.write("<A HREF='http://www.womir.com/'><img src='008.jpg' align=center hspace=10></a>"); return;
 }
 }
 
 RandomGraphics();
 </SCRIPT>
<b>Reload page.</b>
 </body>
 </html>
0
 
LVL 5

Accepted Solution

by:
koolie earned 2000 total points
ID: 17061156
I think you'll find this link is exactly what you are looking for.
http://jscode.com/js_random_image.shtml
It is simple and to the point.  I was going to copy it out, but it will be easier for you from the link
0
 
LVL 5

Expert Comment

by:koolie
ID: 17061181
One other note about the link I posted, if you want to learn off of it it is very well documented
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

762 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