Get Input Text Field - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Introduction

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>
<html>
<body>

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

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

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

<script>
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;
}
</script>

</body>
</html>

Related Tutorials