Javascript Reference - HTML DOM Input Number max Property








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

The max attribute sets the maximum value for a number field.

Browser Support

max Yes Yes Yes Yes Yes

Syntax

Return the max property.

var v = numberObject.max 

Set the max property.

numberObject.max=number




Property Values

Value Description
number Set the maximum value allowed

Return Value

A String type value representing the maximum numeric value allowed.

Example

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:





Example 2

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: