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

HTML DOM Input Datetime required property

Input Datetime required property

Input Datetime Object Reference Input Datetime Object

Example

Check whether the datetime field is a required field before submitting the form:

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

x

The output is:

true

Try it »


Definition and Usage

The required property is used to set or return whether the datetime field is a required field in the form.

This attribute reflects the HTML required attribute.


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the required attribute, except Internet Explorer 9 and earlier versions and the Safari browser.

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


Syntax

Return the required attribute:

datetimeObject

.required

Set the required attribute:

datetimeObject

.required=true|false

Attribute values

Value Description
true|false Describes whether the datetime field is a required part before form submission.
  • true - The datetime field is a required part of the form
  • false - Default. The datetime field is an optional part of the form.
  • |

    Technical Details

    Return Value: Boolean, returns true if the datetime field is a required part of the form, otherwise returns false.

    More examples

    Example

    Set the datetime field as a required part of the form:

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

    Try it »


    Related pages

    HTML Reference Manual: HTML required attribute


    Input Datetime Object Reference Input Datetime Object