Latest web development tutorials
 

Input Password defaultValue Property

< Input Password Object

Example

Change the default value of the password field:

document.getElementById("myPsw").defaultValue = "hello";
Try it Yourself »

Definition and Usage

The defaultValue property sets or returns the default value of a password 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/initial password of the password field, while value is the current password of the password field 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 contents of a password field have been changed.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The defaultValue property is supported in all major browsers.


Syntax

Return the defaultValue property:

passwordObject.defaultValue

Set the defaultValue property:

passwordObject.defaultValue=value

Property Values

Value Description
value Specifies the default value of the password field

Technical Details

Return Value: A String, representing the default value of the password field

More Examples

Example

Return the default value of a password field:

var x = document.getElementById("myPsw").defaultValue;
Try it Yourself »

Example

An example that shows the difference between the defaultValue and value property:

var x = document.getElementById("myPsw");
var defaultVal = x.defaultValue;
var currentVal = x.value;
Try it Yourself »

< Input Password Object