Javascript: document.all null or not an object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Leila

    Javascript: document.all null or not an object

    Folks

    I have an html file which looks like this:

    ..
    ..
    ..
    <body onLoad="WindowO nLoad();">
    ..
    ..
    ..
    <div id="strategy_as p" style="visibili ty:hidden;">HTM L CODE HERE</div>
    <div id="organisatio n_asp" style="visibili ty:hidden;">HTM L CODE
    HERE</div>
    <div id ="people.asp " style="visibili ty:hidden;">HTM L CODE HERE</div>
    ..
    ..
    ..

    I also have a javascript function which retrieves the URL of the page
    you're on and should then display the appropriate content for that
    page:

    function WindowOnLoad() {

    // this function will detect what page I am on using the javascript
    href function
    // and then depending on the outcome, it will switch the <div> tag for
    that particular page
    // on or off

    var src = self.location.h ref;
    src = (src.substring( src.lastIndexOf ("/") + 1,
    src.length).toL owerCase());

    // replace "." in URL with "_"
    src = src.replace('.' , '_')

    if (document.layer s) {
    eval("document. layers['" + src + "'].style.visibili ty = 'show';");
    } else if(document.all ) {
    eval("document. all." + src + ".style.visibil ity = 'visible'");
    } else if(document.get ElementById) {
    eval("document. getElementById( '" + src + "').style.style .visibility =
    'visible';");
    }
    }

    However, I keep getting this error when I click on strategy.asp, for
    example:
    document.all.st rategy_asp.styl e is null or not an object
    This is infuriating. What am I doing wrong???
  • Randy Webb

    #2
    Re: Javascript: document.all null or not an object

    Leila wrote:[color=blue]
    > Folks
    >
    > I have an html file which looks like this:
    >[/color]

    <--snip-->
    [color=blue]
    > if (document.layer s) {
    > eval("document. layers['" + src + "'].style.visibili ty = 'show';");[/color]

    eval not needed at all.
    [color=blue]
    > } else if(document.all ) {
    > eval("document. all." + src + ".style.visibil ity = 'visible'");[/color]

    document.all[src].style.visibili ty
    again, no eval needed.
    [color=blue]
    > } else if(document.get ElementById) {
    > eval("document. getElementById( '" + src + "').style.style .visibility =
    > 'visible';");[/color]

    document.getEle mentById(src).s tyle.visibility

    un-needed eval and an extra .style in it
    [color=blue]
    > }
    > }
    >
    > However, I keep getting this error when I click on strategy.asp, for
    > example:
    > document.all.st rategy_asp.styl e is null or not an object
    > This is infuriating. What am I doing wrong???[/color]

    1) You are using an eval that is not needed.
    2) You probably dont have a div named strategy_asp
    3) You are taking the document.all branch early, take the getElementById
    branch first.

    Comment

    Working...