Input Password value Attribute

Definition and Usage

value Set or return the value of the value attribute of the password field.

The HTML value attribute contains the default value or the value entered by the user (or the value set by the script).

See also:

HTML Reference Manual:HTML <input> value Attribute

Instance

Example 1

Get the value of the value attribute of the password field:

var x = document.getElementById("myPsw").value;

Try It Yourself

Example 2

Change the value of the password field:

document.getElementById("myPsw").value = "NewPassword567";

Try It Yourself

Example 3

An example to show the difference between the defaultValue and value attributes:

var x = document.getElementById("myPsw");
var defaultVal = x.defaultValue;
var currentVal = x.value;

Try It Yourself

Syntax

Return value attribute:

passwordObject.value

Set value attribute:

passwordObject.value = text

Attribute Value

Value Description
text Specifies the value of the password field.

Technical Details

Return Value: A string value representing the password for the password field.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support 10.0 Support Support Support