Randomizing Images using javascript -


ok im trying here: want randomize image under dv id splash , have images placed in root folder. tried randomize code using function randomimg() here output empty. ideas?

<!doctype html public "-//w3c//dtd html 4.01//en" "http://www.w3.org/tr/html4/strict.dtd">  <html xmlns="http://www.w3.org/1999/xhtml" lang="en">   <head>     <meta http-equiv="content-type" content="text/html; charset=utf-8" />     <title>html</title>     <meta name="author" content="blahblahblah" />     <!-- date: 2014-03-06 -->     <script type="text/javascript">       function randomimg()       {         var images = new array();         images[0] = "img06.jpg";         images[1] = "img07.jpg";         images[4] = "img08.jpg";         images[5] = "img09.jpg";         images[6] = "img10.jpg";         var random = math.ceil(math.random()* images.length);         if (random == 0) {  random =1;  }         document.write('<img src="images[random]">');       }     </script>   </head> <body>  <div id="header">   <div id="logo">   <h1><a href="#">welcome</a></h1>   <h2>flower of day</h2>    </div>   <div id="splash"><img src="virus.jpg" alt="random images"/></div>   <script type="text/javascript">      document.getelementbyid('splash').firstelementchild.src = 'img09.jpg';     randomimg();   </script> </div> </body> </html> 

update html:

 <div id="splash"><img id='image' src="virus.jpg" alt="random images"/></div> 

instead of document.write('<img src="images[random]">'); put

document.getelementbyid('image').src=images[random]; 

else

simply replace document.write('<img src="images[random]">'); with

document.getelementbyid('splash').firstelementchild.src =images[random]; 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -