Password valueProperty
Password Object
Definition and Usage
The value property sets or returns the value of the value attribute of the password field.
For security reasons, some browsers may prevent JavaScript code from reading the value property.
Syntax
Set the value property:
passwordObject.value="value"
Return the value property:
passwordObject.value
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the value property
Example
Example
The following example gets the default value of the password field:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example (example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("pwd").value;
alert(x);
}
</script>
</head>
<body>
<form>
Password: <input type="password" id="pwd">
</form>
<button type="button" onclick="displayResult()">Show value</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Example (example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("pwd").value;
alert(x);
}
</script>
</head>
<body>
<form>
Password: <input type="password" id="pwd">
</form>
<button type="button" onclick="displayResult()">Show value</button>
</body>
</html>
Try it Yourself »
Password Object Other Extensions