Using the input Element to Obtain a Number

Description

The number value for the type attribute creates an input box that will only accept numeric values.

The following lists describes the additional attributes that are available when using number input type.

  • list - Sets id of a datalist element that provides values for this element.
  • min - Sets the minimum value for the purposes of input validation.
  • max - Sets the maximum value for the purposes of input validation.
  • readonly - If present, makes the input box read-only, and the user cannot edit the content.
  • required - user must provide a value for the purposes of input validation.
  • step - Sets the step of increments and decrements to the value.
  • value - Specifies the initial value for the element.

The values for the min, max, step, and value attributes can be expressed as integer or decimal numbers; for example, 3 and 3.14.

Example

The following code shows the number type of input in use.


<!DOCTYPE HTML>
<html>
<body>
  <form method="post" action="http://example.com/form">
    <p>
      <label for="price"> $ per unit in your area: <input
        type="number" step="1" min="0" max="100" value="1" id="price"
        name="price" />
      </label>
    </p><!--from  w  w  w. j ava 2  s.c o m-->
    <input type="submit" value="Submit Vote" />
  </form>
</body>
</html>

Click to view the demo





















Home »
  HTML CSS »
    HTML »




HTML Introduction
HTML Document
HTML Section
HTML Group Content
HTML Text Marker
HTML Table
HTML Form
HTML Embed