I have a little JavaScript code I wrote, and for some reason I'm getting an error saying:
ReferenceError: getElementById is not defined
Here is the function:
window.onload=function() { clearAll(); updatePizzaToppings(); updatePizzaToppings(); updatePizzaToppings(); updatePizzaToppings(); }; function updatePizzaToppings() { var checkBox=getElementById('selectBacon'); var pic=getElementById('BaconPic'); if (checkBox.checked) { pic.style.visibility='visible'; } else { pic.style.visibility='hidden'; } };
I've made a little JSFiddle for it as well.
http://jsfiddle.net/CkjkB/5/
This error TypeError: document. getelementbyid(...) is null would seem to indicate that there is no such element with an ID passed to getElementById() exist. This can happen if the JavaScript code is executed before the page is fully loaded, so its not able to find the element.
The getElementById() method returns null if the element does not exist.
The Javascript ReferenceError occurs when referencing a variable that does not exist or has not yet been initialized in the current scope. Reference errors in Javascript are of a few different types, with variations of each, that may get triggered in code. Some of these are discussed below.
You need to use document.getElementById()
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