javascript - TypeError is Null - Stack Overflow

I'm fixing a simple user input mulptiplication table which has been littered with errors.I'm

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
Add a ment  | 

3 Answers 3

Reset to default 2

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?

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744630161a4584810.html

相关推荐

  • javascript - TypeError is Null - Stack Overflow

    I'm fixing a simple user input mulptiplication table which has been littered with errors.I'm

    2天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信