Forms and Input
Read information entered into HTML form fields.
What you should understand
Read the lesson carefully, study the example, then use the editor below to experiment with the code yourself.
<!DOCTYPE html>
<html>
<body>
<input id="name" placeholder="Enter your name">
<button onclick="showName()">Submit</button>
<p id="result"></p>
<script>
function showName() {
let name = document.getElementById("name").value;
document.getElementById("result").textContent =
"Hello " + name;
}
</script>
</body>
</html>
Output
See what your code produces.
Test your understanding
Choose the best answer.
Which method can select an element by its ID?