Javascript Reference - HTML DOM Input Number min Property








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

The min attribute sets the minimum value for a number field.

Browser Support

min Yes 10.0 Yes Yes Yes

Syntax

Return the min property.

var v = numberObject.min

Set the min property.

numberObject.min=number




Property Values

Value Description
number Set the minimum value allowed

Return Value

A String type value representing the minimum numeric value allowed.

Example

The following code shows how to change the minimum value.


<!DOCTYPE html>
<html>
<body>
Quantity:<!-- w w w.ja va  2  s. com-->
<input type="number" id="myNumber" min="1" max="10">
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    var x = document.getElementById("myNumber").min = "5";
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to get the minimum value allowed for a number field.


<!DOCTYPE html>
<html>
<body>
Quantity (between 1 and 5):<!--  w w  w. j ava2s  . c o  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").min;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

The code above is rendered as follows: