Reputation: 15
I'm fixing a simple user input mulptiplication table which has been littered with errors. I'm stuck with a partucular piece of code and do not understand what it means.
When the script is run in firbug it says "TypeError: document.getElementById(...) is null"
This is the code which is attached to html:
var get = function(name){return document.getElementById("name").value;};
var set = function(name,value){document.getElementById("name").value=value;};
Upvotes: 1
Views: 12546
Reputation: 10379
It looks like this code is meant to query the DOM for an element with the id of name
:
var get = function(name){return document.getElementById(name).value;};
var set = function(name,value){document.getElementById(name).value=value;};
Upvotes: 1
Reputation: 43728
That simply means that there is no element with an id
property of "name"
in the DOM. Perhaps your code runs before the document is ready?
Upvotes: 2
Reputation: 261
It means that the element with id = "name"
is not found in document. Look in the dom if it exists.
You can also try to add this code as event handler for ready
-event to check that it works ok there - as it is already said maybe you run this code before the dom is loaded.
Upvotes: 0