The Most Active and Friendliest
Affiliate Marketing Community Online!

“Adavice”/  “1Win

Javascript error - help!

T

trigger

Guest
I have a menu system which I got the code from elsewhere but it throws up an error in IE that says
Line: 7
Char: 11
Error: Object required
Code: 0

the javascript is:

startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes;
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
}
node.onmouseout=function() {
this.className=this.className.replace(" over", "");
}
}
}
}
}
window.onload=startList;

Can anyone help please?
 
PHP:
startList = function() {
    if (document.all && document.getElementById) {
        navRoot = document.getElementById("nav");
        for (i=0; i<navRoot.childNodes.length; i++) {
            node = navRoot.childNodes[i];
            if (node.nodeName=="LI") {
                node.onmouseover=function() {
                    this.className+=" over";
                }
                node.onmouseout=function() {
                    this.className=this.className.replace(" over", "");
                }
            }
        }
    }
}
window.onload=startList;

please provide a live url with this, you cant debug JS that deals with DOM out of context. for example, for this to work you need:

- an element with id "nav" (can be a ol or ul or div)
- child elements encapsulated in <li> tags with a valid className (not null)
- css class '.over'

make sure the li tags have a default classname, for example, list them as <li class="menu-off"><a href=''>something</a></li> - it may be that this.className+=" over"; is throwing the exception if className is not a string property that the element has (hence you can't add to it, you need to create it first) - thats a guess, other than that it needs a debugger.

the line numbering is also rather necessary to look at the error. if its a private project you cannot disclose, then i suggest you go and add firebug lite to your development project and start outputting some debug data, like the child elements the script finds, their events etc.

to be honest, if all you do is add an effect on mouseover on your menu, you can do it in pure css. if this is bosscart, you'd have mootools available and can rewrite it in a cross browser compatible way:

PHP:
window.addEvent("domready", function() {
    $("nav").getElements("li").addEvents({
        "onmouseenter": function() {
            this.addClass("over");
        },
        "onmouseleave": function() {
            this.removeClass("over");
        }
    });
});

you should google the advantages to using a js framework in dealing with cross-browser compatibility issues.
 
Last edited by a moderator:
Nothing to do with your problem at the moment, but have you checked the "Spiderability" of your JavaScript Menu ??

Many of these fancy scripted menus are like prison bars to the SE Bots that would need to follow the links to drill down in your site to retrieve the lower pages. This is a common reason for some sites having only the Home Page indexed.
 
Thanks for that help, I have it fixed now. The problem was that I had modified the css without realising that elements such as ID would be affected in the js. So my ul ID was named something else to the js - once I changed it in the js to match that of the css it worked a treat - no errors!

The menu is primarily css based, from alistapart so it should be seo friendly. The only javascript piece is used to rectify IE issues.

:thumbsup:
 
Dimitar, I am sorry, i suppose it was me who gave you that rep and unfortunetly i don't have admin power here anymore, so i can do nothing to fix this.:crying:
 
nah its cool :) for years i have admined a few vbbs and am all too familiar with the rep war thing, heheh. i tend to turn negative rep off - if you don't have anything nice to say, say nothing at all

anyway - i dont really mind :)
 
MI
Back