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 specified 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 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 defaultValue property:
passwordObject.defaultValue
Indstil defaultValue egenskab:
passwordObject.defaultValue = value
Egenskabsværdi
Værdi | Beskrivelse |
---|---|
value | Definerer standardværdien for et passwordfelt. |
Tekniske detaljer
Returværdi: | Strengværdi, der angiver standardværdien for et passwordfelt. |
---|
Browser support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |