YouTip LogoYouTip

Prop Number Readonly

HTML DOM Input Number readOnly Property

HTML DOM Input Number readOnly Property

-- Learning not just technology, but dreams!

JavaScript Reference

Overview

JavaScript Objects

Browser Objects

DOM Objects

HTML Objects

<input> - month

<input> - range

Input Number readOnly Property

Input Number Object Reference Input Number Object

Example

Set the number field to read-only:

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

Output:

Try it yourself Β»


Definition and Usage

The readOnly property is used to set or return whether a number field is read-only.

A read-only field cannot be modified. However, the content of the field can be copied.

This property reflects the HTML readonly attribute.

Tip: To ensure the accuracy of form data, you can use the disabled property instead.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the readOnly property.

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


Syntax

Get the readOnly property:

numberObject.readOnly

Set the readOnly property:

numberObject.readOnly=true|false

Property Values

Value Description
true|false Specifies whether the number field is read-only

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

Technical Details

Return Value: A Boolean. Returns true if the number field is read-only, otherwise returns false.

More Examples

Example

Check if the number field is read-only:

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

The value of x will be:

true

Try it yourself Β»


Related Pages

HTML Reference: HTML <input> readonly Attribute


Input Number Object Reference Input Number Object

← Prop Number RequiredProp Number Placeholder β†’