Input Time readOnly attribute

Definition and usage

readOnly Attribute to set or return whether the input 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

Instance

Example 1

Set the time field to read-only:

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

Try it yourself

Example 2

Check if the time field is read-only:

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

Try it yourself

Syntax

Return readOnly property:

timeObject.readOnly

Set readOnly property:

timeObject.readOnly = true|false

Attribute value

Value Description
true|false

Specifies whether the time field should be read-only

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

Technical details

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

Browser Support

The numbers in the table indicate the first browser version that fully supports this attribute.

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

Note:The <input type="time"> element does not display as any time field in Firefox.