View Full Version : Javascript help for a noob

09-27-2007, 10:32 AM
Hi there I have recently tried to learn javascript but am now stuck.

I have the following javascript in the head:


var theImages = new Array()

theImages[0] = 'clip1.wmv'
theImages[1] = 'clip2.wmv'
theImages[2] = 'clip3.wmv'
theImages[3] = 'clip4.wmv'

var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<embed src="'+theImages[whichImage]+'">');


and then the following in the body:

<script type="text/javascript">

What i want to know is how to position the showImage(); in an absolute position on the page. Currently it is in the top left corner but i want in 200px from the left and 500px from the top.

Can anyone show me what code I would have to change to get this to work?

Many Thanks,

09-28-2007, 09:51 AM
I'm not into JS but can you not just use a layer (div)!

Are you using Dreamweaver. If so just create a layer positioned where you want the image to go on the page. Then put your..

<script type="text/javascript">

... in the layer.

Hope this is of use.

Regards, Paul

09-28-2007, 08:02 PM
create an empty div and place it in the page where yo want it

<div id="html_here"></div>

in your function where you have....

document.write('<embed src="'+theImages[whichImage]+'">');

change to this...

document.getElementById('html_here').innerHTML = "<embed src="'+theImages[whichImage]+'">";