Click to See Complete Forum and Search --> : java newbie ?.gif location script


Matt A
02-09-2003, 06:33 PM
I want to locate an image on a webpage depending on the date. I think I need to use layers in order to achieve absolute positioning, which the following assumes. Any help (or directions to help) would be appreciated.

When the page is loaded, I want to position an image with absolute coordinates that depend on the date, with no user input.

I have worked out the way to calculate the x and y offsets for the image, and I have java code that gets the date information, but I am too java-illiterate to know how to put the x and y values calculated in the head of the html file into the <div> Layer tag in the body of the html. I suspect I will need an onLoad command in the <body> tag, with a function that passes the values through, or writes a valid <div> for the layer.

I'm out of my depth, but here is my psuedocode.

<head>
<script java yadda yadda>

var xOffset = 0; // initialize
var yOffset = 0; // ditto

var today = getTodayDate;

function locateTheGif( xOffset, yOffset ){
// some mysterious function here
}

xOffset = xMunge(today); // a calculation
yOffset = yMunge(today); // a different calculation

</script>
</head>

<body onload = "locateTheGif()">

<div id="layer1" with absolute location, containing
myGif.gif at location xOffset, yOffset.

</body>
etc..

any suggestions? Thanks.

khalidali63
02-09-2003, 10:53 PM
if you already have the co-ordinates where you will put the image at in the page,then there is not much left to do.

just use DOM to find the elements
assuming that image element has an id attribute with a value.
var img = document.getElementById("imgId");
now use the image reference object to relocate it.

img.style.left = xOffset +"px";
img.style.top = yOffset +"px";

this should position the image at desired point.

cheers

Khalid

Matt A
02-10-2003, 06:42 PM
khalid --

I suspect it's easier than I think, unfortunately, I am too inexperienced to know quite what you mean....

My image has a url, is that what you mean, or do you mean that I assign an id attribute in code?

where does the img.style.left = xOffset + "px"; etc code belong, in the java script or with the image...

you see how much of an ignoramus I am. Maybe there is better way to do it than using a layer? How would you do it if you want to dynamically locate an image on a web page?

thanks, I really appreciate the help.

Matt

Matt A
02-20-2003, 12:07 PM
Khalid --

Thanks. the document object model was the hint I needed, I got it worked out. I appreciate the help.