/    Sign up×
Community /Pin to ProfileBookmark

Hi All,

Am trying to highlight the linkbuttons on click to class name hover ,for these am defining the linkbuttons in Masterpages and calling the function from content page .But am facing below issue .please suggest me some solution

Error:Microsoft JScript runtime error: ‘document.getElementById(…)’ is null or not an object

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@TcobbOct 20.2011 — Its hard to say since there is no code but my best guess is that you are running the code before the document is fully loaded. Wrap the code in a function if its not already and then include, as a separate line that is NOT in a function:

[CODE]window.onload = FuncName;[/CODE]
Copy linkTweet thisAlerts:
@pactor21Oct 20.2011 — Or most likely due to a wrong id of the relevant element.
Copy linkTweet thisAlerts:
@JunkMaleOct 20.2011 — You have a number of ways of tackling this.

As stated with the window onload and dont forget that the HTML <body tag has the property onload="FuncName()" where you can stuff an initializing function like illustrated.

Another is to create "discrete functions" that will run and do not rely on the traditional onload mechanism to trigger. These functions are designed to run after a short delay, it assumes that the page will have loaded in 5 seconds which is a reasnoble assumption to the majority but for some like me, it can take 15 to 20 seconds to load a web page.

[CODE]discrete = {
obj:false,
cycles:0,
StartItUp:function(){
discrete.cycles++; // how many attempts?
try{ // we have the property?
if( discrete.obj=document.getElementById("something")
|| discrete.cycles >99 )

clearInterval( discrete.auto ); // we don't need the call back any more
} catch(e){
delete e; // we do not want the error.
}
},
auto:setInterval("discrete.StartItUp()",5000)
} [/CODE]


start after 5 seconds and stops the callback and makes the variable discrete.obj = the element. If you encounter an error, it should suppress it and the callback is tried again in another 5 seconds and will repeatedly try until it is made or you get to 100 attempts.

The attempts are killed after 99 attempts or 8.33 minutes.
×

Success!

Help @sravan_rathnam spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...