Javascript: document.all null or not an object

Discussion in 'Javascript' started by Leila, Jul 29, 2004.

  1. Leila

    Leila Guest

    Folks

    I have an html file which looks like this:

    ..
    ..
    ..
    <body onLoad="WindowOnLoad();">
    ..
    ..
    ..
    <div id="strategy_asp" style="visibility:hidden;">HTML CODE HERE</div>
    <div id="organisation_asp" style="visibility:hidden;">HTML CODE
    HERE</div>
    <div id ="people.asp" style="visibility:hidden;">HTML 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.href;
    src = (src.substring(src.lastIndexOf("/") + 1,
    src.length).toLowerCase());

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

    if (document.layers) {
    eval("document.layers['" + src + "'].style.visibility = 'show';");
    } else if(document.all) {
    eval("document.all." + src + ".style.visibility = 'visible'");
    } else if(document.getElementById) {
    eval("document.getElementById('" + src + "').style.style.visibility =
    'visible';");
    }
    }

    However, I keep getting this error when I click on strategy.asp, for
    example:
    document.all.strategy_asp.style is null or not an object
    This is infuriating. What am I doing wrong???
    Leila, Jul 29, 2004
    #1
    1. Advertising

  2. Leila

    Randy Webb Guest

    Leila wrote:
    > Folks
    >
    > I have an html file which looks like this:
    >


    <--snip-->

    > if (document.layers) {
    > eval("document.layers['" + src + "'].style.visibility = 'show';");


    eval not needed at all.

    > } else if(document.all) {
    > eval("document.all." + src + ".style.visibility = 'visible'");


    document.all[src].style.visibility
    again, no eval needed.

    > } else if(document.getElementById) {
    > eval("document.getElementById('" + src + "').style.style.visibility =
    > 'visible';");


    document.getElementById(src).style.visibility

    un-needed eval and an extra .style in it

    > }
    > }
    >
    > However, I keep getting this error when I click on strategy.asp, for
    > example:
    > document.all.strategy_asp.style is null or not an object
    > This is infuriating. What am I doing wrong???


    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.
    Randy Webb, Jul 29, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    26,486
    Mike Schilling
    Mar 29, 2006
  2. Cirene
    Replies:
    1
    Views:
    798
    Alexey Smirnov
    Jun 9, 2008
  3. poorna
    Replies:
    0
    Views:
    130
    poorna
    Jul 26, 2007
  4. Jim Ley
    Replies:
    3
    Views:
    196
  5. Gretjns
    Replies:
    3
    Views:
    206
    Richard Cornford
    Oct 7, 2004
Loading...

Share This Page