Javascript DOM HTML Input Month min Property get

Introduction

Get the minimum month and year allowed for a month field:

var x = document.getElementById("myMonth").min;

Click the button to display the value of the min attribute of the month field.

input elements with type=month is not supported in Firefox.

View in separate window

<!DOCTYPE html>
<html>
<body>

Enter a month between 2014-04 and 2014-09 (April to September):
<input type="month" id="myMonth" min="2014-04" max="2014-09">
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {// ww  w .  j  a  v  a  2  s  . c o  m
  var x = document.getElementById("myMonth").min;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

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

The min attribute specifies the minimum value (month and year) for a month field.

The <input type="month"> element is not supported in Firefox.

Value
Description
YYYY-MM


Specifies the minimum month and year allowed.
YYYY - year (e.g. 2020)
MM - month (e.g. 01 for January)

The min property returns a String representing the minimum month and year allowed.




PreviousNext

Related