Javascript DOM HTML Input Date max Property get

Introduction

Get the maximum date allowed for a date field:

var x = document.getElementById("myDate").max;

Click the button to display the value of the max attribute of the date field.

View in separate window

<!DOCTYPE html>
<html>
<body>

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() {//from  w  w w.  j  av a2s .  c  o  m
  var x = document.getElementById("myDate").max;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

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

The max attribute sets the maximum date value for a date field.

The max property accepts and returns a String type value.

Property Value Format

Value
Description
YYYY-MM-DD



Specifies the maximum date allowed for the date field.
YYYY - year (e.g. 2020)
MM - month (e.g. 01 for January)
DD - day of the month (e.g. 08)

For example, "2020-02-09" means February 9th, 2020.




PreviousNext

Related