Click to See Complete Forum and Search --> : Easy Problem


lumberjake2
02-02-2006, 01:41 PM
This is a small script to display a floating box that follows the mouse when the mouse is over a link, but it only brings up the box and doesnt follow the mouse.. If ya get me.


var tid = 0, x = 0, y = 0;

document.onmousemove=track;

function track(e)
{
x = (document.all) ? event.x : e.pageX;
y = (document.all) ? event.y : e.pageY;
}

function show(id)
{
obj = document.getElementById("popup" +id);
obj.style.left = x - 20; / /Error: obj has no properties . It's weird, it only errors on this line of code
but manages to retrieve all the rest of the data from the object,
like the one below.
obj.style.top = y - 45;
obj.style.display = "block";
tid = window.setTimeout("show()",1);
}

function hide(id)
{
obj = document.getElementById("popup" +id);
window.clearTimeout(tid);
obj.style.display = "none";
}


The code should work, as when the getelementbyid line is outside of the function it works perfectly :confused: Anybody help out a noob?? Pleeease.

Wisest Guy
02-02-2006, 02:04 PM
Which object has no properties?

CrazyMerlin
02-02-2006, 02:05 PM
try eval("popup" + id)

lumberjake2
02-02-2006, 02:12 PM
@ Wisest guy

obj = document.getElementById("popup" +id);

this one i think. But it only says it has no properties for this one line of code.

obj.style.left = x - 20;

@ CrazyMerlin.

I dont really know how to use the eval function or know what it does. :confused:

Thanks for the replies guys.

Wisest Guy
02-02-2006, 02:24 PM
Try this:

obj.style.left =
x - 20;

lumberjake2
02-02-2006, 02:27 PM
Nope the same outcome :(

Wisest Guy
02-02-2006, 02:31 PM
But which line is the error on?

lumberjake2
02-02-2006, 02:42 PM
Line 14.

obj.style.left = x - 20;

lumberjake2
02-02-2006, 03:36 PM
Nevermind i fixed it. The timeout wasn't passing the variable id on on recursion, i just changed tid = window.setTimeout("show()",1); to tid = window.setTimeout("show("+id+")",1);

Thanks anyway guys