Solved

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

Posted on 2006-07-07
3
204 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 500 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

730 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