The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

javascript .. after roaming the wastelands of the web

O' javascript gurus, help the hapless!

I have a simple need - I need to display an icon on an image at a specific coordinate. IE 6 is enough.

So I have an image, and a hidden DIV with the necessary background. The image is an ASP.NET image button (therefore an input type="image" and not actually an IMG)

My javascript function takes the image-relative position (i.e. as you would do in a hotspot) but to put the box I need  the coordinate adjusted factoring the position of the image itself.

The function is this:
function GetRealTopAndLeft(img,left,top) {
            var mleft = (img.offsetLeft + left);
            varm mtop = (img.offsetTop + top);
            var tmp = img;
            if(!tmp) {
                alert("image def is null!");
            while (tmp.offsetParent) {
                tmp = tmp.offsetParent;    
                if(!tmp) {
                    alert("no tmp!");
return [mleft,mtop]

This USED to work - i don't know what I changed, can't find anything - but while it works flawlessly in firefox it just doesn't work in IE, I get 0 for everything.. it does loop thru the while, so I know it's getting the parent objects, but the darned things get 0 for all offsetLeft/Top.

What am I doing wrong?!

Thursday, May 12, 2005
The code you posted has so many bugs in it it's hard to follow.

Post soemthing that has a chance of working...
Friday, May 13, 2005
Did you copy the code?

It has errors like missing closing brace for function. +
varm mtop = (img.offsetTop + top); SHOULD BE
var mtop = (img.offsetTop + top);

BTW, is it possible to upload the page so that I can have a look?

JD Send private email
Friday, May 13, 2005

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz