Get Input Text Field - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text


The Input Text object represents an HTML <input> element with type="text".

You can access an <input> element with type="text" by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<input type="text" id="myText" value="Some text...">

<button onclick="myFunction()">get the text in the text field</button>

<p id="demo"></p>

function myFunction() {//from  w w  w  . j a v a  2 s . c  om
    var x = document.getElementById("myText").value;
    document.getElementById("demo").innerHTML = x;


Related Tutorials