Javascript Reference - HTML DOM Input Date value Property








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

Browser Support

value Yes No No Yes Yes

Syntax

Return the value property.

var v = inputdateObject.value 

Set the value property.

inputdateObject.value=YYYY-MM-DD

Property Values

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




Return Value

A String type value representing the date of the date field.

Example

The following code shows how to get the date of a date field.


<!DOCTYPE html>
<html>
<body>
<input type="date" id="myDate" value="2015-05-05">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from w w w  .  java 2 s  .  c  o m-->
    var x = document.getElementById("myDate").value;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to set a date value for a date field.


<!DOCTYPE html>
<html>
<body>
<!--from  w  w w  .  j a v a  2s . c  om-->
Birthday: <input type="date" id="myDate">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    document.getElementById("myDate").value = "2014-02-10";
}
</script>

</body>
</html>

The code above is rendered as follows: