简体   繁体   中英

Getting value from text input using document.getElementByID not working

I'm doing a simple project with javascript and it requires me to get a value out of an HTML text input with javascript. In the following code I've found that nothing after line 6 works and I have no idea why. This has been driving me crazy for like two hours and I'm kind of at my wits end. Please help!

function letsPlayAGame() {
  var answer = Math.floor(Math.random() * 100 + 1);

  var guess = document.getElementByID("theinput").value;

  if (Number.isInteger(guess) == false) {
    document.getElementByID("label").innerHTML =
      "Please enter a number between 1 and 100!";
  } else if (guess < 1 || guess > 100) {
    document.getElementByID("label").innerHTML =
      "Please enter a number between 1 and 100!";
  } else {
    alert("not this part");
  }
}

It should be:

document.getElementById

instead of

document.getElementByID

as Javascript is case sensitive.

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