mikemanx2 Posted March 7, 2006 Share Posted March 7, 2006 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 More sharing options...
scott100 Posted March 7, 2006 Share Posted March 7, 2006 Have a look here: http://w3schools.invisionzone.com/index.php?showtopic=1979or search google for javascript random backgrounds Link to comment Share on other sites More sharing options...
mikemanx2 Posted March 7, 2006 Author Share Posted March 7, 2006 But i dont want random background i want a random image on my page Link to comment Share on other sites More sharing options...
scott100 Posted March 7, 2006 Share Posted March 7, 2006 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 More sharing options...
mikemanx2 Posted March 7, 2006 Author Share Posted March 7, 2006 Thx But one more thing do you no what the html code would be for it Link to comment Share on other sites More sharing options...
calvin182 Posted March 7, 2006 Share Posted March 7, 2006 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 More sharing options...
mikemanx2 Posted March 7, 2006 Author Share Posted March 7, 2006 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 More sharing options...
calvin182 Posted March 7, 2006 Share Posted March 7, 2006 just put the whole entire thing into your html document. Link to comment Share on other sites More sharing options...
scott100 Posted March 8, 2006 Share Posted March 8, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now