Solved

Error with Java Script in IE 8

Posted on 2009-04-02
4
3,922 Views
Last Modified: 2013-11-23
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
Comment
Question by:jeffr1970
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
Thomas4019 earned 500 total points
ID: 24054408
I think you call " l.zIndex " should be " l.style.zIndex " on the error line
0
 

Author Comment

by:jeffr1970
ID: 24054962
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
 
LVL 3

Expert Comment

by:avdej
ID: 24073342
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
 

Author Comment

by:jeffr1970
ID: 24110795
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to debug htl and js pages 8 39
forgetful about js objects 8 46
multiple selects 23 48
on window close, not beforeunload 6 18
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question