Jump to content

Random


mikemanx2

Recommended Posts

Hi im trying to do a random image thing with my frount page. i tryed php by you cant atomaticly run a script in html for php. So if any one can help me please help.

Link to comment
Share on other sites

But i dont want random background i want a random image on my page

Link to comment
Share on other sites

sorry, misread your question

<script language="JavaScript"><!--images = new Array();images[0] = "<img src='http://www.google.co.uk/intl/en_uk/images/logo.gif'>";images[1] = "<img src='http://w3schools.invisionzone.com/style_images/w3sbanner.gif'>";index = Math.floor(Math.random() * images.length);document.write(images[index]);// --></script>

Link to comment
Share on other sites

Thx But one more thing do you no what the html code would be for it

Link to comment
Share on other sites

that generates the html code for it, it's just you have to copy and paste this section over and over again each time incrementing the little number and changing the image source.

images[1] = "<img src='http://w3schools.invisionzone.com/style_images/w3sbanner.gif'>";

just paste the entire script whereever in your html you want the random image to show up

Link to comment
Share on other sites

ware duss it genorate the html code or do i put that code into my html document or do i save it as .js <script language="JavaScript"><!--images = new Array();images[0] = "<img src='http://www.google.co.uk/intl/en_uk/images/logo.gif'>";images[1] = "<img src='http://w3schools.invisionzone.com/style_images/w3sbanner.gif'>";index = Math.floor(Math.random() * images.length);document.write(images[index]);// --></script>

Link to comment
Share on other sites

The html code is stored in an array which is then written to the page with document.write().Paste the entire script i gave you in the <body> of the html document wherever you want the pic to appear.

<body><p>I am a paragraph before the random image</p><script language="JavaScript"><!--images = new Array();images[0] = "<img src='http://www.google.co.uk/intl/en_uk/images/logo.gif'>";images[1] = "<img src='http://w3schools.invisionzone.com/style_images/w3sbanner.gif'>";index = Math.floor(Math.random() * images.length);document.write(images[index]);// --></script><p>I am a paragraph after the random image</p></body>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...