Get Input Month Field - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Month

Introduction

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

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<input type="month" id="myMonth" value="2014-05">

<button onclick="myFunction()">get the month and year of the month field</button>

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

<script>
function myFunction() {//  w ww .  jav a 2s. c om
    var x = document.getElementById("myMonth").value;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials