Javascript DOM HTML Input Text value Property set

Introduction

Change the value of a text field:

document.getElementById("myText").value = "Johnny Bravo";

Click the button to change the value of the text field.

View in separate window

<!DOCTYPE html>
<html>
<body>

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

<script>
function myFunction() {/*from w  ww  . j av a2  s  .c  o  m*/
  document.getElementById("myText").value = "Johnny Bravo";
}
</script>

</body>
</html>

The value property sets or gets the value attribute of a text field.

The value property contains the default value OR the value a user types in.

The value property accepts and returns a String type value.




PreviousNext

Related