Javascript DOM HTML Input Date defaultValue Property set

Introduction

Change the default value of a date field:

document.getElementById("myDate").defaultValue = "2020-02-09";

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

View in separate window

<!DOCTYPE html>
<html>
<body>

Birthday: <input type="date" id="myDate" value="2020-02-10">
<button onclick="myFunction()">Test</button>
<script>
function myFunction() {/* ww w  .j  a va  2  s .  c  om*/
  document.getElementById("myDate").defaultValue = "2020-02-09";
}
</script>

</body>
</html>

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

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

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

If there are no changes, defaultValue and value is the same.

The defaultValue property accepts and returns a String value.




PreviousNext

Related