Javascript DOM HTML Input Text value Property get

Introduction

Get the value of a text field:

var x = document.getElementById("myText").value;

Click the button to display the value attribute of the text field.

View in separate window

<!DOCTYPE html>
<html>
<body>

First Name: <input type="text" id="myText" value="Mickey">
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {/*from   w w w  .j a  v  a2s .  c o m*/
  var x = document.getElementById("myText").value;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related