Input Date defaultValue Property
Example
Change the default value of a date field:
document.getElementById("myDate").defaultValue = "2014-02-09";
Try it Yourself »
Description
The defaultValue property sets or returns the default value of a date field.
Note: The default value is the value specified in the HTML value attribute.
The difference between the defaultValue and value property, is that defaultValue contains the default value, while value contains the current value after some changes have been made. If there are no changes, defaultValue and value is the same (see "More Examples" below).
The defaultValue property is useful when you want to find out whether the date field have been changed.
Browser Support
Property | |||||
---|---|---|---|---|---|
defaultValue | Yes | 12.0 | Yes | Yes | Yes |
Note: <input type="date"> does not show as a proper date field in IE11, and earlier.
Syntax
Return the defaultValue property:
inputdateObject.defaultValue
Set the defaultValue property:
inputdateObject.defaultValue = value
Property Values
Value | Description |
---|---|
value | Specifies the default value of the date field |
Technical Details
Return Value: | A String, representing the default value of the date field |
---|
More Examples
Example
Get the default value of a date field:
var x = document.getElementById("myDate").defaultValue;
Try it Yourself »
Example
An example that shows the difference between the defaultValue and value property:
var x = document.getElementById("myDate");
var defaultVal = x.defaultValue;
var currentVal = x.value;
Try it Yourself »
❮ Input Date Object