Results 1 to 6 of 6

Thread: IE 7 Error Msg on page, "getelementbyID" Null

  1. #1
    Join Date
    Jul 2006
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default IE 7 Error Msg on page, "getelementbyID" Null

    IE shows error on lower left bottom of page. I pin point the cause to my JS script (highlight.js) and not sure how to correct problem.

    Error msg =

    Line 19:
    Char : 2
    Error 'document getElementByID (....)' is null or not an object.
    Code:0
    URL: http://team-raptor.net/myraptor/r50v...n_linkage.html

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It probably means you've tried to select an element that doesn't exist.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    1. The following code you've used in your script only works with IE based browsers.

    Code:
    if (window.attachEvent) window.attachEvent("onload", sfHover);
    Mozilla based browsers uses window.addEventListener in place of window.attachEvent method.

    Due to the above mentioned problem the IE 7 throws an error if you account Mozilla based browser using window.addEventListener you'll get the same error in Firefox also.

    The syntax is as follows

    window.addEventListener(eventType, listener, useCapture)

    EventType: A string representing the event to bind, without the "on" prefix. For example, "click", "mousedown" etc.

    listener: The function or method to associate with the event.

    useCapture: Boolean indicating whether to bind the event as it is propagating towards the target node, (event Capture), or as the event bubbles upwards from the target (event bubble). Set to true or false, respectively.

    2. The code you've used in your script which is mentioned below

    Code:
    var sfEls = document.getElementById("vnav").getElementsByTagName("LI");
    Make sure that the object whose id is vnav has non-null values..

  4. #4
    Join Date
    Jul 2006
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Code Exploiter


    Due to the above mentioned problem the IE 7 throws an error if you account Mozilla based browser using window.addEventListener you'll get the same error in Firefox also.
    So it looks like I got two JS scripts that are wrong. It works in IE 6 and Fire Fox. I just upgraded to IE 7 and it doesn't work returning with a script error. Perhaps I did not catch the ! symbol when I was using IE 6.


    I was about to paste the code last night but the forum had to shut down for an hour for clean up.






    Here's the code:

    Code:
    function hlightpagelink(){
    
    var url=location.href
    
    if(url.indexOf('r50v2/raptor_50v2_collective_servo_tip.htm')>-1)
    document.getElementById('raptor_50v2_collective_servo_tip_link').className='onthispage'
    
    if(url.indexOf('r50v2/raptor_50v2_engine_fan_hub_tip.htm')>-1)
    document.getElementById('raptor_50v2_engine_fan_hub_tip_link').className='onthispage'
    
    if(url.indexOf('r50v2/raptor_50v2_flybar_control_arm_tip.htm')>-1)
    document.getElementById('raptor_50v2_flybar_control_arm_tip_link').className='onthispage'
    
    if(url.indexOf('r50v2/raptor_50v2_pitch_control_arm_tip.htm')>-1)
    document.getElementById('raptor_50v2_pitch_control_arm_tip_link').className='onthispage'
    
    if(url.indexOf('r50v2/raptor_50v2_swash_plate_level_tip.htm')>-1)
    document.getElementById('raptor_50v2_swash_plate_level_tip_link').className='onthispage'
    
    if(url.indexOf('r50v2/raptor_50v2_tail_rotor_hub_tip.htm')>-1)
    document.getElementById('raptor_50v2_tail_rotor_hub_tip_link').className='onthispage'
    
    if(url.indexOf('r50v2/raptor_50v2_aileron_linkage.htm')>-1)
    document.getElementById('raptor_50v2_aileron_linkage_link').className='onthispage'
    
    if(url.indexOf('r50v2/raptor_50v2_elevator_linkage.htm')>-1)
    document.getElementById('raptor_50v2_elevator_linkage_link').className='onthispage'
    
    if(url.indexOf('r50v2/raptor_50v2_collective_linkage.htm')>-1)
    document.getElementById('raptor_50v2_collective_linkage_link').className='onthispage'
    
    if(url.indexOf('r50v2/raptor_50v2_throttle_linkage.htm')>-1)
    document.getElementById('raptor_50v2_throttle_linkage_link').className='onthispage'
    
    if(url.indexOf('r50v2/raptor_50v2_rudder_linkage.htm')>-1)
    document.getElementById('raptor_50v2_rudder_linkage_link').className='onthispage'
    
    if(url.indexOf('r50v2/raptor_50v2_manual.htm')>-1)
    document.getElementById('raptor_50v2_manual_link').className='onthispage'
    
    if(url.indexOf('electronics/fut_9chps_switch_assign.htm')>-1)
    document.getElementById('fut_9chps_switch_assign_link').className='onthispage'
    }
    
    if ( typeof window.addEventListener != "undefined" )
        window.addEventListener( "load", hlightpagelink, false );
    else if ( typeof window.attachEvent != "undefined" )
        window.attachEvent( "onload", hlightpagelink );
    else {
        if ( window.onload != null ) {
            var oldOnload = window.onload;
            window.onload = function ( e ) {
                oldOnload( e );
                hlightpagelink();
            };
        }
        else
            window.onload = hlightpagelink;
    }




    Code:
     
    sfHover = function() {
    	var sfEls = document.getElementById("mainnav").getElementsByTagName("li");
    	for (var i=0; i<sfEls.length; i++) {
    		sfEls[i].onmouseover=function() {
    			this.className+=" sfhover";
    		}
    		sfEls[i].onmouseout=function() {
    			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
    		}
    	}
    }
    if (window.attachEvent) window.attachEvent("onload", sfHover);
    
    
    sfHover = function() {
    	var sfEls = document.getElementById("vnav").getElementsByTagName("LI");
    	for (var i=0; i<sfEls.length; i++) {
    		sfEls[i].onmouseover=function() {
    			this.className+=" sfhover";
    		}
    		sfEls[i].onmouseout=function() {
    			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
    		}
    	}
    }
    if (window.attachEvent) window.attachEvent("onload", sfHover);
    Last edited by Girard Ibanez; 01-10-2007 at 12:03 PM.

  5. #5
    Join Date
    Jul 2006
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I believe I found my problem.

    I have two js scripts in my nav.js

    Will post if any more issues.

    Thanks.

  6. #6
    Join Date
    Sep 2007
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Visit http://www.dynamicdrive.com/forums/s...ad.php?t=24383

    I too got the same problem. Please try to solve it. I need to solve it urgently.

Bookmarks

Posting Permissions

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