The max
property sets or gets the max attribute of a number field.
The max
attribute sets the maximum value for a number field.
max |
Yes | Yes | Yes | Yes | Yes |
Return the max property.
var v = numberObject.max
Set the max property.
numberObject.max=number
Value | Description |
---|---|
number | Set the maximum value allowed |
A String type value representing the maximum numeric value allowed.
The following code shows how to change the maximum value.
<!DOCTYPE html>
<html>
<body>
Quantity:<!-- ww w.ja va 2 s.c om-->
<input type="number" id="myNumber" min="1" max="5">
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
var x = document.getElementById("myNumber").max = "10";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get the maximum value allowed for a number field.
<!DOCTYPE html>
<html>
<body>
Quantity (between 1 and 5):<!--from w w w . j av a 2 s .co m-->
<input type="number" id="myNumber" min="1" max="5">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myNumber").max;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: