YouTip LogoYouTip

Prop Datetime Readonly

HTML DOM Input Datetime readOnly Property

HTML DOM Input Datetime readOnly Property

-- Learning is not just about technology, but also about dreams!

JavaScript Reference Manual

Overview

JavaScript Objects

JavaScript Array Object JavaScript Boolean Object JavaScript Date Object JavaScript Math Object JavaScript Number Object JavaScript String Object JavaScript RegExp Object JavaScript Global Properties/Functions JavaScript Operators JavaScript Error

Browser Objects

Window Object Navigator Object Screen Object History Object Location Object Storage Object

DOM Objects

HTML DOM Document Object HTML DOM Element Object HTML DOM Attribute Object HTML DOM Event Object HTML DOM Console Object CSSStyleDeclaration Object DOM HTMLCollection

HTML Objects

<a> <area> <audio> <base> <blockquote> <body> <button> <canvas> <col> <colgroup> <datalist> <del> <details> <dialog> <embed> <fieldset> <form> <iframe> <frameset > <img> <ins> <input> - button <input> - checkbox <input> - color <input> - date <input> - datetime <input> - datetime-local <input> - email <input> - file <input> - hidden <input> - image <input> - month <input> - number <input> - range <input> - password <input> - radio <input> - reset <input> - search <input> - submit <input> - text <input> - time <input> - url <input> - week <keygen> <link> <label> <legend> <li> <map> <menu> <menuItem> <meta> <meter> <object> <ol> <optgroup> <option> <param> <progress> <q> <script> <select> <source> <style> <table> <td> <th> <tr> <textarea> <title> <time> <track> <video>

<input> - date <input> - datetime-local

Input Datetime readOnly Property

Image 8: Input Datetime Object Reference Manual Input Datetime Object

Example

Set the datetime field to read-only:

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

Output:

Try it Β»


Definition and Usage

The readOnly property is used to set or return whether a datetime 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

Image 9: Internet Explorer Image 10: Firefox Image 11: Opera Image 12: Google Chrome Image 13: Safari

All major browsers support the readOnly property.

Note: Internet Explorer, Firefox, Opera 15 (and later) or Chrome support the <input> element with type="datetime".


Syntax

Get the readOnly property:

datetimeObject.readOnly

Set the readOnly property:

datetimeObject.readOnly=true|false

Property Values

Value Description
true|false Specifies 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: A Boolean. Returns true if the datetime field is read-only, otherwise returns false.

More Examples

Example

Check if the datetime field is read-only:

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

The output of x will be:

true

Try it Β»


Related Articles

HTML Reference Manual: HTML <input> readonly Attribute


Image 14: Input Datetime Object Reference Manual Input Datetime Object

← Prop Datetime RequiredProp Datetime Name β†’