admin管理员组文章数量:1390697
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.
本文标签: javascriptTypeError is NullStack Overflow
版权声明:本文标题:javascript - TypeError is Null - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744630161a2616489.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论