Input Number value Attribute

Definition and Usage

value Sets or returns the value of the value attribute of a numeric field.

The HTML value attribute specifies the default value or the value entered by the user (or the value set by the script).

See also:

HTML Reference Manual:HTML <input> value Attribute

Instance

Example 1

Change the value of a numeric field:

document.getElementById("myNumber").value = "16";

Try It Yourself

Example 2

Get the value of a numeric field:

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

Try It Yourself

Example 3

An example showing the difference between the defaultValue and value attributes:

var x = document.getElementById("myNumber");
var defaultVal = x.defaultValue;
var currentVal = x.value;

Try It Yourself

Syntax

Return value attribute:

numberObject.value

Set value attribute:

numberObject.value = number

Attribute Value

Value Description
number Specifies the initial (default) value for a numeric field.

Technical Details

Return value: String value representing a number.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support 10.0 Support Support Support