Javascript DOM HTML Input Date step Property set

Introduction

Change the day intervals:

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

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

Step = 2 means that the user can only select every second day in the calendar

View in separate window

<!DOCTYPE html>
<html>
<body>

Date: <input type="date" id="myDate">

<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {/*from  w  w w . j av a 2 s .  c  om*/
  document.getElementById("myDate").step = "2";
  document.getElementById("demo").innerHTML = "Step was set to '2'.";
}
</script>

</body>
</html>

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

The step attribute sets the day intervals to choose from.

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

If step="10", you can only select every tenth day in the date calendar.

The step property accepts and returns a number type value.

Default is 1 day.

It returns a number representing the legal day intervals.




PreviousNext

Related