Solved

Error with Java Script in IE 8

Posted on 2009-04-02
4
3,919 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

919 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now