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;};
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;};
Share
Improve this question
edited Dec 21, 2013 at 15:54
Rahul Tripathi
173k33 gold badges291 silver badges339 bronze badges
asked Dec 21, 2013 at 15:52
RD5KRD5K
151 gold badge1 silver badge6 bronze badges
2
-
1
Are you sure is DOM loaded when you call
getElementById
? – Sean Doe Commented Dec 21, 2013 at 15:55 - Thanks guys I think I understand now what I am doing wrong. – RD5K Commented Dec 21, 2013 at 16:09
3 Answers
Reset to default 2That 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?
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;};
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.