Javascript Reference - HTML DOM Input Month Object








The Input Month object represents an HTML <input> element with type="month".

Input Month Object Properties

Property Description
autocomplete Sets or gets the value of the autocomplete attribute of a month field
autofocus Sets or gets if a month field can auto focus when the page loads
defaultValue Sets or gets the default value of a month field
disabled Diable or enable a month field
form Get the form that contains the month field
list Get the datalist that contains the month field
max Sets or gets the max attribute of the month field
min Sets or gets the min attribute of the month field
name Sets or gets the name attribute of a month field
readOnly Sets or gets whether the month field is read-only
required Sets or gets whether the month field must be filled before submitting a form
step Sets or gets the value of the step attribute of the month field
type Get type of the month field
value Sets or gets the value attribute of a month field




Standard Properties and Events

The Input Month object supports the standard properties and events.

Example

We can access an <input> element with type="month" by using getElementById().


<!DOCTYPE html>
<html>
<body>
<input type="month" id="myMonth" value="2014-05">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from   ww  w  . ja  v  a  2 s. c o  m-->
    var x = document.getElementById("myMonth").value;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

We can create an <input> element with type="month" by using the document.createElement() method.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from   w  w w .ja v a 2 s.  co m-->
    var x = document.createElement("INPUT");
    x.setAttribute("type", "month");
    x.setAttribute("value", "2014-01");
    document.body.appendChild(x);
}
</script>

</body>
</html>

The code above is rendered as follows: