'Input returning as undefined
Having trouble getting started tinkering with JS. Need to have a const be equal to the input field. Then onclick alert the value of the input so I can start working on the functions.
HTML CODE
<!DOCTYPE html>
<html>
<head>
<title>Number Checker</title>
<meta charset="UTF-8" />
<meta name="keywords" content="HTML, CSS, Javascript" />
<meta name="description" content="Checks Number" />
<meta name="author" content="Kaden Stewart" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="CSS/number-checker.css" />
<script defer src="./Javascript/number-checker.js"></script>
</head>
<body>
<h1>Number Checker!</h1>
<br>
</br>
<form name="numberchecker" id="numcheck">
<label for="number">Input a Number</label>
<input type="number" id="number" name="number" />
<button onclick="alert(num)">Check!</button>
</form>
</body>
</html>
JavaScript
const num = document.getElementById("number").value;
Solution 1:[1]
Had to throw the line document.getElementById("numberInput").value; under a function like so.
function Check() {
const num = document.getElementById("number").value;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dingi |
