简体   繁体   中英

Code keeps saying “Uncaught TypeError: Cannot set property 'value' of null”

My code keeps returning the same error "Uncaught TypeError: Cannot set property 'value' of null". I can't figure out what it means and I've made many changes to the code to try and fix it without success

var speed = prompt("1000 = Fast PC, 500 = Slow PC")
function makeid() {
  var text = "";
  var possible = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";   //changes depending on code variables

  for (var i = 0; i < 14; i++)   //changes depending on code length
    text += possible.charAt(Math.floor(Math.random() * possible.length));

  return text;
}


function main() {
    document.getElementById("INPUTBOXNAME").value = makeid(); //INPUTBOXNAME is placeholder
    document.getElementById("SUBMITBUTTONNAME").click(); //SUBMITBUTTONNAME is placeholder
}

setInterval(function() {
    main();
}, speed);

Could really appreciate some help. Thanks

document.getElementById("INPUTBOXNAME") seems to be returning null in this case. Therefore, you could start by checking if your markup really has an element with an id equal to INPUTBOXNAME . Most probably it will not be the case, or there will be a typo there.

Explanation: This error message means that you are trying to do null.value = something; somewhere in your code. To debug this kind of problem, you should look for the places in your code where you are trying to set the value property of an object, and think of a reason why that object could possibly be a null instead of what was expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM