Javascript DOM HTML Input Month Object get

Introduction

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

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

We can access an <input> element with type="month" via document.getElementById():

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

Click the button to get the month and year of the month field.

View in separate window

<!DOCTYPE html>
<html>
<body>
<input type="month" id="myMonth" value="2014-05">
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {/*www. j a  v  a 2  s .  com*/
  var x = document.getElementById("myMonth").value;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related