• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3931
  • Last Modified:

Error with Java Script in IE 8

IE 8 has broken our online programs.  I work for a small insurance company.  Our agents do there quotes online, and with IE 8 I started getting calls that they couldn't do any quotes.  I told them that we haven't had the time yet to take a look at IE 8 and to roll back to IE 7 for now.  The problem is in our drop down menus.  It is a simple mouse over menu that drops down sub menus.  What is happening is when you mouse over one of the sub menus it hilights the proper color but when you move on to the sub menu below that one it stays blue and gives us an error of "Invalid Argument" in our menu.js.  Line number is 446 and character 9.  A snippet of the code is included.  The menu.js program wasn't written by us, and from what I have been told it hasn't been modified.  Although that might not be correct.  There is also no one in our office that has a really good understanding of java script.  We have just picked up piece here and there as we needed to.  I've marked the line that IE 8 is telling us has the "Invalid Argument".
if (l.hilite) {
            l.document.bgColor = l.menuHiliteBgColor;
            l.zIndex = 1;
            l.hilite.visibility = "inherit";
            l.hilite.zIndex = 2;
            l.document.layers[1].zIndex = 1;
            l.focusItem.zIndex = this.zIndex +2;
        }
        l.focusItem.top = this.top;
        l.Menu.hideChildMenu(l);
    } else if (document.all && l.style && l.Menu) {
        document.onmousedown=l.Menu.onMenuItemDown;
        if (a) {
            a.style.backgroundColor = a.saveColor;
            if (a.hilite) a.hilite.style.visibility = "hidden";
        } else {
            a = new Object();
		}
        if (l.mouseover && l.id != a.id) {
            if (l.mouseover.length > 4) {
                var ext = l.mouseover.substring(l.mouseover.length-4);
                if (ext == ".gif" || ext == ".jpg") {
                    l.document.images[l.id + "Img"].src = l.mouseover;
                } else {
                    eval("" + l.mouseover);
                }
            }
        }
		if (l.isSeparator) return;
        l.style.backgroundColor = l.menuHiliteBgColor;
        if (l.hilite) {
            l.style.backgroundColor = l.menuHiliteBgColor;
            l.hilite.style.visibility = "inherit";
        }
        l.focusItem.style.pixelTop = l.style.pixelTop;
        l.focusItem.style.zIndex = l.zIndex +1;           <------Error Line
        l.zIndex = 1;
        l.Menu.hideChildMenu(l);
    } else if (document.getElementById){
        document.onmousedown=l.Menu.onMenuItemDown;	
        if (a) {
	        a.style.backgroundColor = a.saveColor;
    	    if (a.hilite) a.hilite.style.visibility = "hidden";
        } else {
            a = new Object();
        }
        if (this.mouseover && this.id != a.id) {
            if (this.mouseover.length > 4) {
                var ext = this.mouseover.substring(this.mouseover.length-4);
                if (ext == ".gif" || ext == ".jpg") {
                    document.images[l.id + "Img"].src = this.mouseover;
                } else {
                    eval("" + this.mouseover);
                }
            }
        }

Open in new window

0
jeffr1970
Asked:
jeffr1970
  • 2
1 Solution
 
Thomas4019Commented:
I think you call " l.zIndex " should be " l.style.zIndex " on the error line
0
 
jeffr1970Author Commented:
That fixed that problem.  What we don't understand though, is why did something that simple break our programs in IE 8 but since around IE 3 or 4 it has worked without any issues.  Is this something that probably shouldn't of worked all these years?  

0
 
avdejCommented:
I'm afraid the previous solution may be unsafe and may (under certain conditions) destroy some sensible logic behind the menu behavior.

Object 'l' seems to be a global data holder and 'l.zIndex' seems to be a 'reference' zIndex value that will be used to properly place the element currently focused.

The cause of the problem is that at a very first call of that method l.zIndex has an 'undefined' value (some 'init.js' file missing?), which added to 1 evaluates to NaN. Probably IE 8 does not want to accept that NaN value as a valid zIndex value anymore.

In my opinion, the better solution would be to place JUST BEFORE that error line the following harmless line of code:

l.zIndex = l.zIndex == null ? 1 : l.zIndex;

It will fix the problem as well AND will not affect the following menu behavior.

Dear, jeffr1970, please NOTE
IF you accept a solution and write in your comment: "That fixed that problem..."
THEN it is time to close the question, to select one or more answers that helped AND to provide a grade.

Regards,
Avdej
0
 
jeffr1970Author Commented:
Let me try that out and I'll close this out tomorrow.  I apologize for the delay, I had a personal issue come up and I'm just now getting back to work.  Where as putting "l.style.zindex" worked, I was hoping for some type of reasoning on why it has worked with every version of IE until IE 8.  That is why I asked ANOTHER question in my response.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now