HTML DOM Input DatetimeLocal max Property


The HTML DOM Input DatetimeLocal max property returns/sets max attribute of Input DatetimeLocal.

Syntax

Following is the syntax −

  • Returning string value
inputDatetimeLocalObject.max
  • Setting max to string value
inputDatetimeLocalObject.max = YYYY-MM-DDThh:mm:ss

String Values

Here, “YYYY-MM-DDThh:mm:ss” can be the following −

stringValueDetails
YYYYIt defines year (eg:2006)
MMIt defines month (eg: 06 for June).
DDIt defines Day (eg: 17)
TIt is a separator for date and time
hhIt defines hour (eg:02)
mmIt defines minutes (eg:21)
ssIt defines seconds (eg:40)

Example

Let us see an example of Input DatetimeLocal max property −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>Input DatetimeLocal max</title>
<style>
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   * {
      padding: 2px;
      margin:5px;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style>
</head>
<body>
<form>
<fieldset>
<legend>Datetime-Local-max</legend>
<label for="datetimeLocalSelect">Insurance Expiration:
<input type="datetime-local" id="datetimeLocalSelect" value="2019-07-01T23:59:59" max="2019-08-01T23:59:59" disabled>
</label>
<input type="button" onclick="renewInsurance()" value="Renew Insurance">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputDatetimeLocal = document.getElementById("datetimeLocalSelect");
   function renewInsurance() {
      inputDatetimeLocal.max = '2029-07-01T23:59:59';
      inputDatetimeLocal.value = inputDatetimeLocal.max;
      divDisplay.textContent = 'Renewed Insurance: '+inputDatetimeLocal.value;
   }
</script>
</body>
</html>

Output

This will produce the following output −

Before clicking ‘Renew Insurance’ button −

After clicking ‘Renew Insurance’ button −

Updated on: 30-Jul-2019

67 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements