Change the default value of the password field:
document.getElementById("myPsw").defaultValue = "hello";
Click the button to display the default value of the password field.
<!DOCTYPE html> <html> <body> Password: <input type="password" id="myPsw" value="password123"> <button type="button" onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {// ww w .j a va 2 s .co m var x = document.getElementById("myPsw").defaultValue; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The defaultValue property sets or gets the default value of a password field.
The default value is the value specified in the HTML value attribute.
The defaultValue contains the initial password, while value is the current password.
If there are no changes, defaultValue and value is the same.
The defaultValue property accepts and returns a String type value.