Javascript DOM HTML Input Text defaultValue Property set

Introduction

Change the default value of a text field:

document.getElementById("myText").defaultValue = "Java";

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

View in separate window

<!DOCTYPE html>
<html>
<body>

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

<script>
function myFunction() {/*from  ww  w .  j  ava2  s  . co m*/
  document.getElementById("myText").defaultValue = "Java";
}
</script>

</body>
</html>

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

The default value is the value set in the HTML value attribute.

The defaultValue contains the default value, while value contains the current value.

The defaultValue property accepts and returns a String type value.




PreviousNext

Related