Uncaught TypeError [closed]
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this questionCan anyone explain what is theses errors?
Uncaught TypeError: Cannot set property 'innerHTML' of null
Uncaught TypeError: Cannot read property 'style' of null
Uncaught SyntaxError: Unexpected token ILLEGAL
Uncaught TypeError: Object # has no method 'dispatchEvent'
This is my test Website
At some point in the page you have:
function display_price(price, oid)
{
...
element = document.getElementById(oid);
if (valor != 'NaN' && valor != null && valor != '')
{
element.innerHTML = valor + money_simbol;
The last line is causing the error because element
is null. You should add a condition to the if(): that is, change this line:
if (valor != 'NaN' && valor != null && valor != '')
to this:
if (element && valor != 'NaN' && valor != null && valor != '')
In other words, it's a good practice to always check the return value of a function before accessing its properties.
You call the function display_price
passing it ID of span
that does not yet exist.
Change this line: (appears twice in your code)
display_price('510', 'products_price_id');
To this instead:
window.onload = function() {
display_price('510', 'products_price_id');
};
This will wait until the page loads before trying to find the element, thus solve your errors.
精彩评论