Input Number readOnly attribute

Definition and usage

readOnly Attribute to set or return whether the numeric field should be read-only.

Read-only fields cannot be modified. However, users can select, highlight it, and copy text from it.

This property reflects the HTML readonly attribute.

Tip:To prevent users from interacting with the field, use disabled attribute.

See also:

HTML Reference Manual:HTML <input> readonly Attribute

Example

Example 1

Set the numeric field to read-only:

document.getElementById("myNumber").readOnly = true;

Try it yourself

Example 2

Determine if the numeric field is read-only:

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

Try it yourself

Syntax

Return the readOnly property:

numberObject.readOnly

Set the readOnly property:

numberObject.readOnly = true|false

Attribute value

Value Description
true|false

Define whether the numeric field should be read-only.

  • true - The numeric field is read-only
  • false - Default. The numeric field is not read-only

Technical Details

Return value: Boolean value, if the numeric field is read-only, it returns true; otherwise return false.

Browser Support

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