Javascript DOM HTML Input Month stepDown() Method

Introduction

Decrement the value of a month field by 3 months:

Click the button to decrement the value of the month field by 3 months.

The stepDown() method is not supported by Firefox.

View in separate window

<!DOCTYPE html>
<html>
<body>

Month and year: <input type="month" id="myMonth" value="2020-11">

<button onclick="myFunction()">Test</button>
<script>
function myFunction() {// w  ww  . j a v  a  2s  .  c  o  m
  document.getElementById("myMonth").stepDown(3);
}
</script>

</body>
</html>

The stepDown() method decrements the value of the month field by a specified number.

This method will only have an affect on Months.

Parameter Description
numberRequired. Specifies the amount of months the month field should decrease.

If omitted, the months are decremented by "1"




PreviousNext

Related