The max
attribute from date field
specifies the maximum value (date) for a date field.
The max
property sets or gets the value of the max attribute of a date field.
max |
Yes | No | No | Yes | Yes |
Return the max property.
var v = inputdateObject.max
Set the max property.
inputdateObject.max=YYYY-MM-DD
Value | Description |
---|---|
YYYY-MM-DD | Set the maximum date value allowed for the date field.
|
A String type value representing the maximum date allowed.
The following code shows how to change the maximum date.
<!DOCTYPE html>
<html>
<body>
Date:<!--from w w w . j a v a 2 s . co m-->
<input type="date" id="myDate" name="bday" min="1980-01-01" max="2000-01-01">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myDate").max = "2014-01-01";
document.getElementById("demo").innerHTML = "changed";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get the maximum date allowed for a date field.
<!DOCTYPE html>
<html>
<body>
<!-- www. j a va 2 s . c o m-->
Enter a date between 1980-01-01 and 2000-01-01:
<input type="date" id="myDate" name="bday" min="1980-01-01" max="2000-01-01">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myDate").max;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: