JavaScript querySelector() method - get text input value
by danielkwood
HTML
<html>
<head>
<title>querySelector() method</title>
</head>
<body>
<p>Please enter your name</p>
<input type="text" id="myTextInput"/>
<button id="myButton">Submit</button>
<p id="message"></p>
</body>
</html>
JavaScript
document.querySelector("#myButton").addEventListener("click", getTextInput);
function getTextInput(){
var myTextInput = document.querySelector("#myTextInput").value;
document.querySelector("#message").innerHTML = "Hello, " + myTextInput;
}