Latest web development tutorials
 

Input Number value Property

< Input Number Object

Example

Change the number of a number field:

document.getElementById("myNumber").value = "16";
Try it Yourself »

Definition and Usage

The value property sets or returns the value of the value attribute of a number field.

The value attribute specifies the default value OR the value a user types in (or a value set by a script).


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The value property is supported in all major browsers.

Note: The <input type="number"> element is not supported in Internet Explorer 9 and earlier versions.


Syntax

Return the value property:

numberObject.value

Set the value property:

numberObject.value=number

Property Values

Value Description
number Specifies the initial (default) value of the number field

Technical Details

Return Value: A String, representing a number

More Examples

Example

Get the number of a number field:

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

The result of x will be:

2
Try it Yourself »

Example

An example that shows the difference between the defaultValue and value property:

var x = document.getElementById("myNumber");
var defaultVal = x.defaultValue;
var currentVal = x.value;
Try it Yourself »

Related Pages

HTML reference: HTML <input> value attribute


< Input Number Object