Javascript Reference - HTML DOM Input Date max Property








The max attribute from date field specifies the maximum value (date) for a date field.

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

Browser Support

max Yes No No Yes Yes

Syntax

Return the max property.

var v = inputdateObject.max 

Set the max property.

inputdateObject.max=YYYY-MM-DD




Property Values

Value Description
YYYY-MM-DD Set the maximum date value allowed for the date field.
  • YYYY - year (e.g. 2014)
  • MM - month (e.g. 01 for January)
  • DD - day of the month (e.g. 09)

Return Value

A String type value representing the maximum date allowed.

Example

The following code shows how to change the maximum date.


<!DOCTYPE html>
<html>
<body>
Date:<!--from w  w w .  j  a v a 2 s  .  co  m-->
<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").max = "2014-01-01";
    document.getElementById("demo").innerHTML = "changed";
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to get the maximum date allowed for a date field.


<!DOCTYPE html>
<html>
<body>
<!-- www. j a  va  2  s .  c o  m-->
Enter a date between 1980-01-01 and 2000-01-01:
<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").max;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: