Javascript Reference - HTML DOM Input Month max Property








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

The max attribute sets the maximum month and year value for a month field.

Browser Support

max Yes No No Yes Yes

Syntax

Return the max property.

var v = monthObject.max 

Set the max property.

monthObject.max=YYYY-MM




Property Values

Value Description
YYYY-MM Sets the maximum month and year allowed.
  • YYYY - year (e.g. 2014)
  • MM - month (e.g. 01 for January)

Return Value

A String type value representing the maximum month and year allowed.

Example

The following code shows how to change the maximum month and year.


<!DOCTYPE html>
<html>
<body>
<!--from  ww  w . j  a  v a  2s .c o  m-->
Month:
<input type="month" id="myMonth" min="2014-04" max="2014-09">
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    var x = document.getElementById("myMonth").max = "2014-12";
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to get the maximum month and year allowed for a month field.


<!DOCTYPE html>
<html>
<body>
<!--from w w w.  ja va  2 s  .  co m-->
Enter a month between 2014-04 and 2014-09:
<input type="month" id="myMonth" min="2014-04" max="2014-09">
<button onclick="myFunction()">test</button>
<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myMonth").max;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: