Input Password defaultValue Attribute
Definition and Usage
defaultValue
Sets or returns the default value of the password field.
Note:The default value is HTML value attribute defined by.
The difference between defaultValue and value properties is that defaultValue contains the default/initial password of the password field, while value is the current password of the password field after some changes. If there is no change, defaultValue and value are the same (see the example below).
The defaultValue property is very useful if you want to check whether the content of the password field has been changed.
Instance
Example 1
Change the default value of the password field:
document.getElementById("myPsw").defaultValue = "hello";
Example 2
Return the default value of the password field:
var x = document.getElementById("myPsw").defaultValue;
Example 3
An example to show the difference between defaultValue and value properties:
var x = document.getElementById("myPsw"); var defaultVal = x.defaultValue; var currentVal = x.value;
Syntax
Return the defaultValue property:
passwordObject.defaultValue
Set defaultValue Property:
passwordObject.defaultValue = value
Attribute Value
Value | Description |
---|---|
value | Specifies the default value of the password field. |
Technical Details
Return Value: | A string value representing the default value of the password field. |
---|
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |