I am getting this error when I call a javascript function to display a modal window:
Microsoft JScript runtime error: ‘document.getElementById(…)’ is null or not an object
The code block is:
else if (action=="officeview") {
document.getElementById("OfficeContent").src="ChangeView.aspx";
ShowFeatureModal('AppView','OfficeContent')
The object is this situation, does exist.
Error is caused at: document.getElementById line.
What else could be causing the error?
Update:
Index.aspx is calling the javascript function which is located in sysUtilities.js file. The source file is yet a seperate page (ChangeView.aspx)
If
document.getElementByIddoesn’t find the element, it will returnnull. If you then try to get thesrcproperty fromnull, you’ll get this error.You’ll either need to ensure the there’s an element with its ID equal to
OfficeContentor do something like the following:EDIT: If you’re using ASP.NET, which it appears that you are, remember that your IDs might be getting name-mangled if they are inside a container control. In that case, you have to make sure to use the
ClientID, not the plain oldID. Something like this: