HTML DOM Input Date max Property

HTMLWeb DevelopmentFront End Technology

The HTML DOM Input Date max property returns/sets max attribute of Input date type.

Syntax

Following is the syntax −

  • Returning string value
inputDateObject.max
  • Setting max to string value
inputDateObject.max = YYYY-MM-DD

String Values

Here, “YYYY-MM-DD” can be the following −

stringValueDetails
YYYYIt defines year (eg:1998)
MMIt defines month (eg: 05 for May)
DDIt defines Day (eg: 24)

Example

Let us see an example of Input Date max property −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>Input Date Max</title>
</head>
<body>
<form>
Date Select: <input type="date" id="date" name="DateSelect" max="2018-12-31">
</form>
<button onclick="getMaxDate()">Change Max Date</button>
<div id="divDisplay"></div>
<script>
   var inputDate = document.getElementById("date");
   var divDisplay = document.getElementById("divDisplay");
   divDisplay.textContent = 'Max of date input: '+inputDate.max;
   function getMaxDate() {
      var oldInputDate = inputDate.max;
      inputDate.max = '2020-12-31';
      divDisplay.textContent = 'Max of date input: '+inputDate.max;
   }
</script>
</body>
</html>

Output

This will produce the following output −

Before clicking ‘Change Max Date’ button −

After clicking ‘Change Max Date’ button −

raja
Published on 19-Jul-2019 11:12:26

Advertisements