javascript - Uncaught TypeError: Cannot read property 'value' of null, need some direction - Stack Overflow

I have been trying to figure out this particular problem in my developer tools, but I've had no lu

I have been trying to figure out this particular problem in my developer tools, but I've had no luck thus far. I have an error on one of my js files that says

Uncaught TypeError: Cannot read property 'value' of null 

The following error refers to the 1st variable of dt_version below. The particular thing is if I ment out the first line of code. I get the same error on the following variables of offload1 and offload2. The variable is a number that I am trying to get passed over. I run this function on my body when the page loads...onload=updatetotal();

    function updatetotal() {
    var dt_version = document.getElementById("dt_version").value-0;
    var offload1 = document.getElementById("capacity_offload1").value-0;
    var offload2 = document.getElementById("capacity_offload2").value-0;
    var offload3 = document.getElementById("capacity_offload3").value-0;
    }

If a run an if statement looking for document.getElementByID("dt_version");...it defaults to false..so its not being carried over though on the previous page, I can see its input fine with the value in it. What am I missing here guys?

I have been trying to figure out this particular problem in my developer tools, but I've had no luck thus far. I have an error on one of my js files that says

Uncaught TypeError: Cannot read property 'value' of null 

The following error refers to the 1st variable of dt_version below. The particular thing is if I ment out the first line of code. I get the same error on the following variables of offload1 and offload2. The variable is a number that I am trying to get passed over. I run this function on my body when the page loads...onload=updatetotal();

    function updatetotal() {
    var dt_version = document.getElementById("dt_version").value-0;
    var offload1 = document.getElementById("capacity_offload1").value-0;
    var offload2 = document.getElementById("capacity_offload2").value-0;
    var offload3 = document.getElementById("capacity_offload3").value-0;
    }

If a run an if statement looking for document.getElementByID("dt_version");...it defaults to false..so its not being carried over though on the previous page, I can see its input fine with the value in it. What am I missing here guys?

Share Improve this question asked Dec 12, 2012 at 18:15 wowzuzzwowzuzz 1,39011 gold badges31 silver badges51 bronze badges 1
  • are you sure you have elements with those ID in your page? – wirey00 Commented Dec 12, 2012 at 18:18
Add a ment  | 

2 Answers 2

Reset to default 1

This error means that the id dt_version does not exist. Check your html to make sure it is there:

var dt =  document.getElementById("dt_version");
if (dt){
   // do your stuff
}else {
    console.log("dt does not exist")
}

Another cause for this error may be- as you are calling the javascript function on page load there is a possible chance that your control is not yet pletely rendered to the page. A simple solution is just move that control to the beginning of the page. If it doesn't work then an reliable solution is, call the function inside jquery $(document).ready().

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

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信