Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM Input Datetime readOnly property

Input Datetime readOnly property

Input Datetime Object Reference Input Datetime Object

Example

Set the datetime field to read-only:

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

Output result:

Try it »


Definition and Usage

The readOnly property is used to set or return whether the datetime field is read-only.

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

This attribute reflects the HTML readonly attribute.

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


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the readOnly attribute.

Note: Supported by Internet Explorer, Firefox, Opera 15 (and later), or Chrome. element using type="datetime".


Syntax

Return the readOnly attribute:

datetimeObject

.readOnly

Set the readOnly attribute:

datetimeObject

.readOnly=true|false

Attribute values

Value Description
true|false Describes whether the datetime field is read-only
  • true - The datetime field is read-only
  • false - Default. The datetime field is not read-only
  • |

    Technical Details

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

    More examples

    Example

    Check whether the datetime field is read-only:

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

    x

    The output is:

    true

    Try it »


    Related Articles

    HTML Reference Manual: HTML readonly attribute


    Input Datetime Object Reference Input Datetime Object