Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Junior Member carbongixxer's Avatar
    Join Date
    Sep 2008
    Posts
    1
    Member #
    17314
    Hey guys,
    On all my pages I get the following error, "null" is null or not an object .
    After doing some searching I found that it is a script error. I believe the error is somewhere in this section of code, but cannot find it. Any help would be appreciated.

    function cascadedstyle(el, cssproperty, csspropertyNS){
    if (el.currentStyle)
    return el.currentStyle[cssproperty]
    else if (window.getComputedStyle){
    var elstyle=window.getComputedStyle(el, "")
    return elstyle.getPropertyValue(csspropertyNS)
    }
    }

    var previoustab=""

    function expandcontent(cid, aobject){
    if (document.getElementById){
    highlighttab(aobject)
    detectSourceindex(aobject)
    if (previoustab!="")
    document.getElementById(previoustab).style.display ="none"
    document.getElementById(cid).style.display="block"
    previoustab=cid
    if (aobject.blur)
    aobject.blur()
    return false
    }
    else
    return true
    }

    function highlighttab(aobject){
    if (typeof tabobjlinks=="undefined")
    collecttablinks()
    for (i=0; i<tabobjlinks.length; i++)
    tabobjlinks[i].style.backgroundColor=initTabcolor
    var themecolor=aobject.getAttribute("theme")? aobject.getAttribute("theme") : initTabpostcolor
    aobject.style.backgroundColor=document.getElementB yId("tabcontentcontainer").style.backgroundColor=t hemecolor
    }

    function collecttablinks(){
    var tabobj=document.getElementById("tablist")
    tabobjlinks=tabobj.getElementsByTagName("A")
    }

    function detectSourceindex(aobject){
    for (i=0; i<tabobjlinks.length; i++){
    if (aobject==tabobjlinks[i]){
    tabsourceindex=i //source index of tab bar relative to other tabs
    break
    }
    }
    }

    function do_onload(){
    var cookiecheck=window.get_cookie && get_cookie(window.location.pathname).indexOf("|")! =-1
    collecttablinks()
    initTabcolor=cascadedstyle(tabobjlinks[1], "backgroundColor", "background-color")
    initTabpostcolor=cascadedstyle(tabobjlinks[0], "backgroundColor", "background-color")
    if (typeof enablepersistence!="undefined" && enablepersistence && cookiecheck){
    var cookieparse=get_cookie(window.location.pathname).s plit("|")
    var whichtab=cookieparse[0]
    var tabcontentid=cookieparse[1]
    expandcontent(tabcontentid, tabobjlinks[whichtab])
    }
    else
    expandcontent(initialtab[1], tabobjlinks[initialtab[0]-1])
    }

    if (window.addEventListener)
    window.addEventListener("load", do_onload, false)
    else if (window.attachEvent)
    window.attachEvent("onload", do_onload)
    else if (document.getElementById)
    window.onload=do_onload
    </script>
    <script type="text/javascript">
    //Dynamicdrive.com persistence feature add-on
    var enablepersistence=true //true to enable persistence, false to turn off (or simply remove this entire script block).

    function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) {
    offset += search.length
    end = document.cookie.indexOf(";", offset);
    if (end == -1) end = document.cookie.length;
    returnvalue=unescape(document.cookie.substring(off set, end))
    }
    }
    return returnvalue;
    }

    function savetabstate(){
    document.cookie=window.location.pathname+"="+tabso urceindex+"|"+previoustab
    }

    window.onunload=savetabstate
    </script>

  2.  

  3. #2
    Senior Member Shani's Avatar
    Join Date
    Nov 2004
    Posts
    1,140
    Member #
    8171
    It's hard to say exactly because I'm not able to see the script in action, but I encountered the same error recently, so it might be the same thing.

    In my case, there was dynamic content:
    PHP Code:
    <?php 
    if (whatever) { 
      echo 
    '<div id="happy">happy content</div>';
    }
    ?>
    My script had something like this:
    Code:
    document.getElementById('happy').innerHTML = "some other crazy happy content";
    What happened was when the whatever condition wasn't being met, the happy div wasn't on the page, so the document.getElementById threw an object error.
    Shani

    I have an eye for detail like you'd never believe.

  4. #3
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    The reason the two of you are getting "'null' is null or not an object" is because you're not assigning the element to a variable before accessing its properties.

    If you split your code up into more lines, you'll get more meaningful errors.

    In Shani's case:

    Code:
    var happyElement = document.getElementById('happy');
    happyElement.innerHTML = "some other crazy happy content";
    Then, her error would be "happyElement is null or not an object" <--- as you can see, much more meaningful.

    She could further go a step further to ensure that she doesn't get any errors by adding the following:


    Code:
    var happyElement = document.getElementById('happy');
    if (happyElement) {
        happyElement.innerHTML = "some other crazy happy content";
    }

  5. #4
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Oh, and carbon, that script you posted is a mess, but you can apply the same rules in my last post to it and that should prevent the error from happening, though it probably won't solve your problem, because the root of the problem is that "document.getElementById" isn't finding the element in question.

  6. #5
    Senior Member Shani's Avatar
    Join Date
    Nov 2004
    Posts
    1,140
    Member #
    8171
    Transio is correct. And in my defense, I had properly assigned the variable I guess then my solution was to the "not an object" part rather than the null.
    Shani

    I have an eye for detail like you'd never believe.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search tags for this page

offset is null or is not an object

Click on a term to search for related topics.
All times are GMT -6. The time now is 05:39 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com