The value
property sets or gets the value attribute of a password field.
value |
Yes | Yes | Yes | Yes | Yes |
Return the value property.
var v = passwordObject.value
Set the value property.
passwordObject.value= text
Value | Description |
---|---|
text | Set the value of the password field |
A String type value representing the password of the password field.
The following code shows how to change the value of the password field.
<!DOCTYPE html>
<html>
<body>
<!--from www . j a va 2 s. com-->
<form>
Password: <input type="password" id="myPsw">
</form>
<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 is: " + x);
}
function change() {
var x = document.getElementById("myPsw").value = "NewPassword";
console.log("The value was changed to: " + x);
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get the value attribute of a password field.
<!DOCTYPE html>
<html>
<body>
Password: <input type="password" id="myPsw" value="mypwd345">
<button onclick="myFunction()">test</button>
<!-- w w w. j av a 2s . c o m-->
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myPsw").value;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: