Javascript Reference - HTML DOM Input Time max Property








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

The max attribute specifies the maximum time for a time field.

Browser Support

max Yes No No Yes Yes

Syntax

Return the max property.

var v = timeObject.max 

Set the max property.

timeObject.max=hh:mm:ss.ms




Property Values

Value Description
hh:mm:ss.ms Set the maximum time allowed for the time field.
  • hh - hour (e.g. 22 for 10.00pm)
  • mm - minutes (e.g. 31)
  • ss - seconds (e.g. 01)
  • ms - milliseconds (e.g 21)

Return Value

A String type value representing the maximum time allowed for the time field.

Example

The following code shows how to change the maximum time allowed.


<!DOCTYPE html>
<html>
<body>
<!--from   ww w  . j  av  a  2  s .c o m-->
Time: <input type="time" id="myTime" min="20:00" max="22:00">
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    var x = document.getElementById("myTime").max = "23:00";
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to get the maximum time allowed for a time field.


<!DOCTYPE html>
<html>
<body>
<!--from w  ww .  j a va 2  s  .co  m-->
Time: <input type="time" id="myTime" min="20:00" max="22:00">
<button onclick="myFunction()">test</button>

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

<script>
function myFunction() {
    var x = document.getElementById("myTime").max;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: