Javascript DOM HTML Input Month step Property set

Introduction

Change the legal month intervals:

document.getElementById("myMonth").step = "2";

Click the button to change the value of the step attribute of the month field.

The step property is not supported in Firefox.

View in separate window

<!DOCTYPE html>
<html>
<body>

Month: <input type="month" id="myMonth">
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {/*from www .  j  a va  2  s .c  om*/
  document.getElementById("myMonth").step = "2";
  document.getElementById("demo").innerHTML = "Step was set to '2', meaning that the user can only select every second month in the calendar.";
}
</script>

</body>
</html>

The step property sets or gets the value of the step attribute of a month field.

The step attribute sets the month intervals to choose from when the user opens the calendar in the month field.

For example, if step = "2", you can only select every second month in the calendar.

The <input type="month"> element is not supported in Firefox.

The step property accepts and returns a number type value.

Default is 1 month.




PreviousNext

Related