Input Password defaultValue Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Password

Description

The defaultValue property sets or gets the default value of a password field, which is the value specified in the HTML value attribute.

You can use defaultValue to find out whether the contents of a password field have been changed.

Set the defaultValue property with the following Values

Value Description
value Sets the default value of the password field

Return Value

A String, representing the default value of the password field

The following code shows how to change the default value of the password field:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>
Password: <input type="password" id="myPsw" value="pass123">

<button type="button" onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from   w w  w. j av a  2s.co m
    document.getElementById("myPsw").defaultValue = 'adsf';
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials