Input Time defaultValue attribute

Definition and usage

defaultValue Sets or returns the default value of the time field.

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

The difference between defaultValue and value attributes is that 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 "More examples").

The defaultValue attribute is very useful if you want to check whether the time in the time field has changed.

Instance

Example 1

Change the default value of the time field:

document.getElementById("myTime").defaultValue = "18:00";

Try it yourself

Example 2

Get the default value of the time field:

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

Try it yourself

Example 3

An example to show the difference between defaultValue and value attributes:

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

Try it yourself

Syntax

Return the defaultValue attribute:

timeObject.defaultValue

Set the defaultValue attribute:

timeObject.defaultValue = value

Attribute value

Value Description
value Specifies the default value of the time field.

Technical Details

Return Value: A string value representing the default value of the 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="time"> element does not display as any time field in Firefox.