<input> - datetime


HTML DOM Input Datetime object


Input Datetime object

The Input Datetime object is new in HTML5.

Input Datetime objects represent HTML <input> elements using the type="datetime" attribute.

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

Access the Input Datetime object

You can use the getElementById() function to access <input> elements with the type="datetime" attribute:

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

Tip: You can also access the Input Datetime object through the form's elements collection.

 Try It! 

Create an Input Datetime object

You can use the document.createElement() method to create an <input> element with the type="datetime" attribute:

var x = document.createElement("INPUT");
x.setAttribute("type", "datetime");

Try It! 

Input Datetime Object Attributes

AttributeDescription
autocompleteSets or returns the value of the autocomplete attribute of the datetime field
autofocusSets or returns whether the datetime field automatically gets focus after page load
defaultValueSet or return the default value of the datetime field
disabledSets or returns whether the datetime field is disabled
formReturns a form reference using a datetime field
listReturns a datalist reference containing datetime fields
maxSets or returns the value of the max attribute of a datetime field
minSets or returns the value of the min attribute of a datetime field
nameSets or returns the value of the name attribute of a datetime field
readOnlySets or returns whether the datetime field is read-only
requiredSets or returns whether the datetime field is required in the form
stepSets or returns the value of the step attribute of a datetime field
typeReturns the form element type of the datetime field
valueSets or returns the value of the datetime field's value attribute

Standard Properties and Events

Input Datetime objects also support standard properties and events .


Related articles

HTML Tutorial: HTML Forms

HTML Reference Manual: HTML <input> Tag

HTML Reference Manual: HTML <input> type attribute