Input Date min Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Date

Description

The min property sets or gets the min attribute of a date field, which controls the minimum date for a date field.

Set the min property with the following Values

Value Description
YYYY-MM-DD Sets the minimum date allowed 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 minimum date allowed

The following code shows how to get the minimum date allowed for a date field:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>
Date://  www .ja v  a  2  s.  c om
<input type="date" id="myDate" name="bday" min="1980-01-01" max="2000-01-01">

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

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

<script>
function myFunction() {
    var x = document.getElementById("myDate").min;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials