I am getting the following error in Google Chrome on a very old Form I inherited (seems to work OK in IE, no errors)
Uncaught TypeError: Cannot read property 'firstChild' of null
The error applies to the following js elem.firstChild.nodeValue = dispmessage;:
function msg(fld,
msgtype,
message) {
if (emptyString.test(message))
dispmessage = String.fromCharCode(nbsp);
else
dispmessage = message;
var elem = document.getElementById(fld);
elem.firstChild.nodeValue = dispmessage;
elem.className = msgtype; // set the CSS class to adjust appearance of message
};
Wondering if someone has come across similar issue before? Any ideas on how I can resolve?
Cheers
The Uncaught TypeError: Cannot read properties of null (reading 'firstChild') is a common error in JavaScript. There can be two reasons behind occurring this error and the solutions to this problem are easy. The reasons behind occurring this problem are either you type a wrong id or you misplaced the script for linking the JS file into HTML.
Uncaught TypeError: Cannot read property 'value' of null Uncaught TypeError: Cannot read property 'innerHTML' of null All this means is that you are trying to access a property of an object that is undefined. These usually happens when we don't test an object before using it. Here is a common scenario.
Sometimes instead of null it will say undefined. An example will be: Uncaught TypeError: Cannot read property 'value' of null. Uncaught TypeError: Cannot read property 'innerHTML' of null. All this means is that you are trying to access a property of an object that is undefined. These usually happens when we don't test an object before using it.
This error occurs when you read a property or call a method on a null object . That's because the DOM API returns null for object references that are blank. An object is expected somewhere and wasn't provided. So, you will get null is not an object error if the DOM elements have not been created before loading the script.
This error means the elem
object is null
. Check the fld value passed and see whether an object with that id actually exists in your code or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With