<p>
<label for="theNumber">
Enter a number between 0 and 400 that is divisible by 5:
</label>
<input type="number" step="5" id="theNumber" min="0" max="400" />
</p>
<p>
<label>
Enter how many values of step you would like to increment by or leave it
blank:
</label>
<input type="number" step="1" id="incrementInput" min="0" max="25" />
</p>
<input type="button" value="Increment" id="theButton" />HTMLInputElement: stepUp() method / notebook
HTMLInputElement: stepUp() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
input:invalid {
border: red solid 3px;
}/* make the button call the function */
const button = document.getElementById("theButton");
button.addEventListener("click", () => {
stepOnUp();
});
function stepOnUp() {
let input = document.getElementById("theNumber");
let val = document.getElementById("incrementInput").value;
if (val) {
/* increment with a parameter */
input.stepUp(val);
} else {
/* or without a parameter. Try it with 0 */
input.stepUp();
}
}