Forum Moderators: open

Message Too Old, No Replies

FireFox JavaScript problem

         

nbozic

7:00 pm on Jan 25, 2005 (gmt 0)

10+ Year Member



Hi,

I use a script that uses absolute positioning to place a certain <span> on a specific spot on the webpage.

This code works perfectly in IE, but it chokes if one uses FireFox:
e.parentElement.offsetTop

I get this error in FireFox:
"e.parentElement has no properties"

(
Here are some details.
e is the object of interest - a form textbox. It's passed to the function as "this", then becomes "e" inside the function. I'm trying to position the popup box (<span>) so that it's exactly aligned with the textbox.
)

Thanks!

NB

kaled

7:08 pm on Jan 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's a wild stab-in-the-dark guess but :-

Are you using getElementById()
Are you using <span id="aName">

If the answer to either is no, you have the answer to your question.

If the answer is yes, you'd better post an abbreviated form of the code.

Kaled.

nbozic

9:13 pm on Jan 25, 2005 (gmt 0)

10+ Year Member



I didn't use getElementById(), but it's not relevant to this problem.
What I'm trying to do is find the absolute position of the textbox on the webpage. It was easy when the textbox was alone by itself. I simply passed it to the javascript function as "this".

<input type=textbox onFocus="call_function(this)"...

Then inside the function I would get the position of the textbox:

function call_function(e){

top_position = e.offsetTop;
left_position = e.offsetLeft;
...
...

This used to give me the EXACT numbers I needed to position the <span> right next to the textbox.

Things changed once I put the textbox inside a centered table.

If I used the exact code as above, I would get the position of the textbox relative to the table (since the textbox is inside the table now), and not the position in the whole webpage. This would now allow me the position the <span> where I want it.

Because of that I also need to find out the offset positions of the <td> and <table> elements that the textbox resides in.
I tried doing something like this, and it works fine in IE, but it throws errors in FireFox:

function call_function(e){

top_position = e.offsetTop + [e.parentElement.offsetTop];
left_position = e.offsetLeft + e.parentElement.offsetLeft;
...
...

The code in brackets, which is supposed to refer to the <td> element (the brackets are not included in the original code), throws the error in FireFox, saying that "e.parentElement has no properties"

Any ideas?

Thanks!

NB

Bernard Marx

9:25 pm on Jan 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



e.parentNode!

nbozic

10:06 pm on Jan 25, 2005 (gmt 0)

10+ Year Member



Thanks, e.parentNode works great! :)

The answer seems very simple, I guess I don't know much about non-IE browsers.