Input Password value Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Password

Description

The value property sets or gets the value attribute of a password field.

Set the value property with the following Values

Value Description
text Sets the value of the password field

Return Value

A String, representing the password of the password field

The following code shows how to get the value of the value attribute of a password field:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form>
Password: <input type="password" id="myPsw">
</form>// ww  w  .j  av a2  s . c  o  m

<button onclick="display()">Display value</button>
<button onclick="change()">Change value</button>

<script>
function display() {
    var x = document.getElementById("myPsw").value;
    console.log("The value of the password field is: " + x);
}

function change() {
    var x = document.getElementById("myPsw").value = "NewPassword123";
    console.log("The value was changed to: " + x);
}
</script>

</body>
</html>

Related Tutorials