The Input Text object represents an HTML <input> element with type="text".
We can access an <input> element with type="text" via document.getElementById()
:
var x = document.getElementById("myText");
Click the button to get the text in the text field.
<!DOCTYPE html> <html> <body> <input type="text" id="myText" value="Some text..."> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {// w w w . j a v a 2 s . c o m var x = document.getElementById("myText").value; document.getElementById("demo").innerHTML = x; } </script> </body> </html>