PDA

View Full Version : IE 7 Error Msg on page, "getelementbyID" Null



Girard Ibanez
01-10-2007, 04:45 AM
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/r50v2/raptor_50v2_aileron_linkage.html

Twey
01-10-2007, 10:06 AM
It probably means you've tried to select an element that doesn't exist.

codeexploiter
01-10-2007, 10:06 AM
1. The following code you've used in your script only works with IE based browsers.


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


var sfEls = document.getElementById("vnav").getElementsByTagName("LI");

Make sure that the object whose id is vnav has non-null values..

Girard Ibanez
01-10-2007, 11:52 AM
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:


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;
}







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);

Girard Ibanez
01-10-2007, 12:22 PM
I believe I found my problem.

I have two js scripts in my nav.js

Will post if any more issues.

Thanks.

BNVSAJ
09-06-2007, 06:37 AM
Visit http://www.dynamicdrive.com/forums/showthread.php?t=24383

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