Javascript DOM HTML Input Time step Property

Introduction

Change the legal number intervals for seconds in a time field:

document.getElementById("myTime").step = "10";

Click the button to change the value of the step attribute of the time field for seconds interval.

View in separate window

<!DOCTYPE html>
<html>
<body>

Time: <input type="time" id="myTime" step="2">
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//w  w  w. j  a  v  a  2  s  . c  om
  document.getElementById("myTime").step = "10";
  document.getElementById("demo").innerHTML = "The value of the step attribute was changed.";
}
</script>

</body>
</html>

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

The step attribute sets the number intervals for seconds or milliseconds in a time field.

Example: if step="2", legal numbers could be 0, 2, 4, etc.

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

The step property accepts and returns a number type value.

Value
Description
number




Specifies the legal number intervals in the time field.
For seconds: Use numbers that will eventually reach "60".
Like: "1, "2", "10", "30", etc.
For milliseconds: Start with "." and use numbers that eventually will reach "1000".
Like ".010", ".050", ".20", etc.

The step property return a Number representing the legal number intervals for seconds or milliseconds.




PreviousNext

Related