Input Date value Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Date

Description

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

Set the value property with the following Values

Value Description
YYYY-MM-DD Sets a date for the date field.
  • YYYY - year (e.g. 2011)
  • MM - month (e.g. 01 for January)
  • DD - day of the month (e.g. 08)

An example: "2018-02-09" means February 9th, 2018 (09/02/2018).

Return Value

A String, representing the date of the date field

The following code shows how to Set a date for a date field:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<input type="date" id="myDate" value="2000-05-05">

<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {/*  w ww  . j  a  v  a 2 s .  c o m*/
    document.getElementById("myDate").value = '2001-01-01';
    var x = document.getElementById("myDate").value;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials