Javascript DOM HTML Input Number min Property get

Introduction

Get the minimum value allowed for a number field:

var x = document.getElementById("myNumber").min;

Click the button to display the value of the min attribute of the number field.

View in separate window

<!DOCTYPE html>
<html>
<body>

Quantity (between 1 and 5)://from w  w  w  . j a v  a2 s  . 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 min property sets or gets the value of the min attribute of a number field.

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

The min property accepts and returns a number type value.




PreviousNext

Related