Input DatetimeLocal defaultValue attribute

Definition and usage

defaultValue Set or return the default value of the local date and time field.

Note:The default value is HTML value attribute as specified.

The difference between defaultValue and value attributes is:

  • defaultValue contains the default value
  • while value contains the current value after some changes
  • If there is no change, defaultValue and value are the same (see the example below)

The defaultValue attribute is very useful if you want to check whether the local date and time field has been changed.

Instance

Example 1

Change the default value of the local date and time field:

document.getElementById("myLocalDate").defaultValue = "2015-01-02T11:42:13.510";

Try it yourself

Example 2

Get the default value of the local date and time field:

var x = document.getElementById("myLocalDate").defaultValue;

Try it yourself

Example 3

Here is an example showing the difference between the defaultValue and value attributes:

var x = document.getElementById("myLocalDate");
var defaultVal = x.defaultValue;
var currentVal = x.value;

Try it yourself

Syntax

Return the defaultValue attribute:

datetimelocalObject.defaultValue

Set the defaultValue attribute:

datetimelocalObject.defaultValue = value

Attribute value

Value Description
value Specify the default value of the local date and time field.

Technical Details

Return Value: A string value that represents the default value of the local date and time field.

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="datetime-local"> element does not display any date and time fields/calendar in Firefox.