Javascript Reference - HTML DOM Input Month min Property








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

The min attribute sets the minimum month and year value for a month field.

Browser Support

min Yes No No Yes Yes

Syntax

Return the min property.

var v = monthObject.min

Set the min property.

monthObject.min=YYYY-MM




Property Values

Value Description
YYYY-MM Set the minimum month and year allowed.
  • YYYY - year (e.g. 2011)
  • MM - month (e.g. 01 for January)

Return Value

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

Example

The following code shows how to change the minimum value.


<!DOCTYPE html>
<html>
<body>
<!--from w  ww.j av a 2 s.  co 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").min= "2014-01";
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

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


<!DOCTYPE html>
<html>
<body>
<!--from w  w w.  j av a 2s.  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").min;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: