Input Date max Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Date


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

Set the max property with the following Values

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

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
Date://from w w w . j  av  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>

function myFunction() {
    var x = document.getElementById("myDate").max = "2018-01-01";
    document.getElementById("demo").innerHTML = "changed from '2000-01-01' to '2018-01-01'.";


Related Tutorials