<input> - number


HTML DOM Input Number object


InputNumber object

The Input Number object is new in HTML5.

Input Number objects represent HTML <input> elements with type="number".

Note: Internet Explorer 9 and earlier versions of IE do not support <input> elements with the type="number" attribute.

Access the Input Number object

You can use the getElementById() function to access <input> elements with the type="number" attribute:

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

Try It! 

Tip: You can also access the Input Number object through the form's elements collection.

Create an InputNumber object

You can use the document.createElement() method to create an <input> element with the type="number" attribute:

var x = document.createElement("INPUT");
x.setAttribute("type", "number");

Try It! 

Input Number Object Attributes

AttributeDescription
autocompleteSets or returns the value of the autocomplete attribute of the number field
autofocusSets or returns whether the number field automatically gets the focus after the page loads
defaultValueSet or return the default value of the number field
disabledSets or returns whether the number field is available
formReturns a form reference using the number field
labelsReturns a list of label elements for the number field
listReturns a datalist reference containing the number field
maxSets or returns the value of the max attribute of the number field
minSets or returns the value of the min property of the number field
nameSets or returns the value of the name attribute of the number field
placeholderSets or returns the value of the placeholder property of the number field
readOnlySets or returns whether the number field is read-only
requiredSets or returns whether the number field is required in the form
stepSets or returns the value of the step attribute of the number field
typeReturns the form element type of the number field
valueSets or returns the value of the value attribute of the number field

Standard Properties and Events

Input Number objects also support standard properties and events .


Related articles

HTML Tutorial: HTML Forms

HTML Reference Manual: HTML <input> Tag

HTML Reference Manual: HTML <input> type attribute