HTML code for random images help?

DeletedUser

Guest
Hi,
I have currently got a code like this

HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta content="mshtml 6.00.2800.1264" name="generator" />
<title>Random Images</title>

<script type="text/javascript">
//<![CDATA[
 
var images=new Array();
      images[0]="http://i.imm.io/6Y8e.png";
      images[1]="http://i.imm.io/6Y7B.png";
      images[2]="http://i.imm.io/6Y8e.png";
      images[3]="http://i.imm.io/6Y8s.png";
      images[4]="http://i.imm.io/6Y8C.png";
      images[5]="http://i.imm.io/6Y8N.png";
      images[6]="http://i.imm.io/6Y8e.png";
      images[7]="http://i.imm.io/6Y8s.png";
      images[8]="http://i.imm.io/6Y8C.png";
      images[9]="http://i.imm.io/6Y8N.png";

var i=Math.floor(Math.random()*images.length); 

function randomImage() {

          document.getElementById("random").src=images[i];         
   }

onload=randomImage;
 
//]]>
</script>

</head>
<body>

<div>
<img id="random" alt="random image" src="" />
</div>

</body>
</html>

but when i put in a widget like this one (moving penguins :) )

HTML:
<object type="application/x-shockwave-flash" style="outline:none;" data="http://penguinsgadget.googlecode.com/svn/trunk/penguins.swf?up_backgroundImage=http://i.imm.io/6QAT.png&up_penguinsName=Penguins&up_numPenguins=5&up_&up_numBabies=3&" width="700" height="250"><param name="movie" value="http://penguinsgadget.googlecode.com/svn/trunk/penguins.swf?up_backgroundImage=http://i.imm.io/6TEM.png&up_penguinsName=Penguins&up_numPenguins=25&up_backgroundColor=ffffff&up_numBabies=23&"></param><param name="AllowScriptAccess" value="always"></param><param name="wmode" value="opaque"></param><param name="scale" value="noscale"/><param name="salign" value="tl"/></object>

I cannot get it working. Is there anyway to get a code which allows me to get the widgets/games things to change when I refresh the page, thanks
 

DeletedUser5

Guest
Perfectly possible, but it's more difficult than changing the src of images.

Most objects will have different parameters, so I'd say that the easiest way to do this would be to add and remove elements. This way for each object, you will have the correct parameters available.
 

DeletedUser

Guest
You're nearly there anyway Tyroncs.

As AC04 says, you need to referring to a more general object rather than an img tag and corresponding JS.

change

<img id="random" alt="random image" src="" />

for a normal <div> tag, keep the id the same. Then in Javascript we have the innerHTML property which is very useful (although quite powerful - watch out when it replaces a whole section of your page).

so you can replace your array elements to be the complete <img src=".." /> object, and then do:

document.getElementById("random").innerHTML=images;

I'm sure you can then do the rest.

Let us know how it goes!

P.S. When doing arrays the way you are going to, use the ' and " quotes to separate like follows:

images[0]='<img src="blah.html" />';

see?
 
Top