...

View Full Version : Can't figure out Javascript Error in IE, works in Firefox



bradwbowman
06-14-2007, 04:55 AM
Hi all and thanks,

I get the following error in my coding: I'm not sure if this means I have to declare this as a variable. It works fine in Firefox, but not in IE. Any suggestions or can anyone point me in the right direction? Thanks a bunch.

Line: 268

Error 'offsetParent.offsetLeft' is null or not an object
Code: 0

Here is the function

function hideElement( elmID, overDiv ) {
if(document.all) {
for(i = 0; i < document.all.tags( elmID ).length; i++) {
obj = document.all.tags( elmID )[i];
if(!obj || !obj.offsetParent) continue;
// Find the element's offsetTop and offsetLeft relative to the BODY tag.
LINE 268::) objLeft = obj.offsetLeft - overDiv.offsetParent.offsetLeft;
objTop = obj.offsetTop;
objParent = obj.offsetParent;
while(objParent.tagName.toUpperCase() != 'BODY') {
objLeft += objParent.offsetLeft;
objTop += objParent.offsetTop;
objParent = objParent.offsetParent;}
objHeight = obj.offsetHeight;
objWidth = obj.offsetWidth;
if((overDiv.offsetLeft + overDiv.offsetWidth) <= objLeft);
else if((overDiv.offsetParent.offsetTop + overDiv.offsetHeight + 20) <= objTop);
else if(overDiv.offsetParent.offsetTop >= eval(objTop + objHeight));
else if(overDiv.offsetLeft >= eval(objLeft + objWidth));
else {
obj.style.visibility = 'hidden';
}

}
}
}

digital-ether
06-14-2007, 10:08 AM
Hi all and thanks,

I get the following error in my coding: I'm not sure if this means I have to declare this as a variable. It works fine in Firefox, but not in IE. Any suggestions or can anyone point me in the right direction? Thanks a bunch.

Line: 268

Error 'offsetParent.offsetLeft' is null or not an object
Code: 0

Here is the function

function hideElement( elmID, overDiv ) {
if(document.all) {
for(i = 0; i < document.all.tags( elmID ).length; i++) {
obj = document.all.tags( elmID )[i];
if(!obj || !obj.offsetParent) continue;
// Find the element's offsetTop and offsetLeft relative to the BODY tag.
LINE 268::) objLeft = obj.offsetLeft - overDiv.offsetParent.offsetLeft;
objTop = obj.offsetTop;
objParent = obj.offsetParent;
while(objParent.tagName.toUpperCase() != 'BODY') {
objLeft += objParent.offsetLeft;
objTop += objParent.offsetTop;
objParent = objParent.offsetParent;}
objHeight = obj.offsetHeight;
objWidth = obj.offsetWidth;
if((overDiv.offsetLeft + overDiv.offsetWidth) <= objLeft);
else if((overDiv.offsetParent.offsetTop + overDiv.offsetHeight + 20) <= objTop);
else if(overDiv.offsetParent.offsetTop >= eval(objTop + objHeight));
else if(overDiv.offsetLeft >= eval(objLeft + objWidth));
else {
obj.style.visibility = 'hidden';
}

}
}
}


I believe is the smilie face in your code that is causing the problem..

:)

Try adding a conditional statement that makes sure offsetParent.offsetLeft is an object.


if (typeof(offsetParent.offsetLeft) == 'object') { // do stufff }

document.all - that looks a bit archaic..

Bill Posters
06-14-2007, 10:44 AM
I believe is the smilie face in your code that is causing the problem..
Fwiw, that's being thrown in by the CodingForums post parser as it encounter the :) character combination and won't be part of their original code.
This can be prevented by selecting Disable smilies in text in the Additional Options on post form pages.

digital-ether
06-17-2007, 07:52 AM
Fwiw, that's being thrown in by the CodingForums post parser as it encounter the :) character combination and won't be part of their original code.
This can be prevented by selecting Disable smilies in text in the Additional Options on post form pages.

Sorry, that was meant to be a joke.

I also made an error in my suggestion, it should have been:


if (typeof(offsetParent) == 'object') { // do stufff }

You should make sure the offsetParent is an 'object' (As all HTMLElements are). Then try to access a property.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum