Password defaultValueProperty
Password Object
Definition and Usage
The defaultValue property sets or returns the default value of the password field.
Note:This default value is the default value specified in the HTML "value" attribute.
Syntax
Setting the defaultValue property:
passwordObject.defaultValue="value"
Returning the defaultValue property:
passwordObject.defaultValue
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the defaultValue property
Examples
Examples
The following example gets the default value of the password field:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
function displayResult(){
var x=document.getElementById("pwd").defaultValue;
alert(x);
}
</script>
</head>
<body>
<form>
Password: <input type="password" id="pwd" value="thgrt456">
</form>
<button type="button" onclick="displayResult()">Show default value</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<script>
function displayResult(){
var x=document.getElementById("pwd").defaultValue;
alert(x);
}
</script>
</head>
<body>
<form>
Password: <input type="password" id="pwd" value="thgrt456">
</form>
<button type="button" onclick="displayResult()">Show default value</button>
</body>
</html>
Try it Yourself »
Password Object Other Extensions