The HTMLInputElement.stepUp()
method increments the value of a numeric type of <input>
element by the value of the step
attribute, or the default step
value if the step attribute is not explicitly set. The method, when invoked, increments the value
by (step
* n), where n
defaults to 1
if not specified, and step
defaults to the default value for step
if not specified.
Input type | Default step value | Example step declaration |
---|---|---|
date |
1 (day) | 7 day (one week) increments:<input type="date" min="2019-12-25" step="7">
|
month |
1 (month) | 12 month (one year) increments:<input type="month" min="2019-12" step="12">
|
week |
1 (week) | Two week increments:<input type="week" min="2019-W23" step="2">
|
time |
60 (seconds) | 900 second (15 minute) increments:<input type="time" min="09:00" step="900">
|
datetime-local |
1 (day) | Same day of the week:<input type="datetime-local" min="019-12-25T19:30"
step="7">
|
number | 1 | 0.1 increments<input type="number" min="0" step="0.1" max="10">
|
range | 1 | Increments by 2:<input type="range" min="0" step="2" max="10">
|
The method, when invoked, changes the form control's value by the value given in the step
attribute, multiplied by the parameter, within the constraints set on the form control. The default value for the parameter, if no value is passed, is 1
. The method will not cause the value to exceed the set max
value, or defy the constraints set by the step
attribute.
If the value before invoking the stepUp()
method is invalid—for example, if it doesn't match the constraints set by the step attribute—invoking the stepUp()
method will return a value that does match the form controls constraints.
If the form control is non time, date, or numeric in nature, and therefore does not support the step
attribute (see the list of supported input types in the table above), or if the step value is set to any
, an InvalidStateError
exception is thrown.