Input Date defaultValue attribute
Definition and usage
defaultValue
Sets or returns the default value of the date field.
Note:The default value is HTML value attribute specified value.
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 find out if the date field has been changed.
Instance
Example 1
Change the default value of the date field:
document.getElementById("myDate").defaultValue = "2014-02-09";
Example 2
Get the default value of the date field:
var x = document.getElementById("myDate").defaultValue;
Example 3
An example to show the difference between defaultValue and value attributes:
var x = document.getElementById("myDate"); var defaultVal = x.defaultValue; var currentVal = x.value;
Syntax
Return the defaultValue attribute:
inputdateObject.defaultValue
Set the defaultValue attribute:
inputdateObject.defaultValue = value
Attribute value
Value | Description |
---|---|
value | Specifies the default value of the date field. |
Technical Details
Return Value: | A string value that represents the default value of the date field. |
---|
Browser Support
The numbers in the table indicate the first browser version that fully supports this property.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | 10.0 | Support | Support | Support |
Note:The <input type="date"> element does not display any date field/calendar in IE11 and earlier versions.