Javascript DOM HTML Input Month defaultValue Property get

Introduction

Get the default value of a month field:

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

Click the button to display the default value of the month field.

View in separate window

<!DOCTYPE html>
<html>
<body>
Month and year: <input type="month" id="myMonth" value="1997-11">

<button onclick="myFunction()">Test</button>

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

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

</body>
</html>



PreviousNext

Related