Javascript DOM HTML Input Text defaultValue Property get

Introduction

Get the default value of a text field:

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

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

View in separate window

<!DOCTYPE html>
<html>
<body>

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

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

<script>
function myFunction() {//from www  .  j a v a2 s .  com
  var x = document.getElementById("myText").defaultValue;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related