Javascript DOM HTML Input Date value Property set

Introduction

Set a date for a date field:

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

Click the button to set a date for the date field.

View in separate window

<!DOCTYPE html>
<html>
<body>

Birthday: <input type="date" id="myDate">

<button onclick="myFunction()">Test</button>
<script>
function myFunction() {/*from  w  w w  .  j  a  v a  2 s.  c o m*/
  document.getElementById("myDate").value = "2020-02-09";
}
</script>

</body>
</html>

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

The value attribute sets a date value for the date field.

The value property accepts and returns a String type value.

Value
YYYY-MM-DD



Description
Specifies a date for the date field.
YYYY - year (e.g. 2020)
MM - month (e.g. 01 for January)
DD - day of the month (e.g. 08)

For example: "2020-02-09" means February 9th, 2014.




PreviousNext

Related