Javascript DOM HTML Input Month value Property get

Introduction

Get the month and year of a month field:

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

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

View in separate window

<!DOCTYPE html>
<html>
<body>

Month and year: <input type="month" id="myMonth" value="2020-11">
<button onclick="myFunction()">Test</button>

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

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

</body>
</html>



PreviousNext

Related