The placeholder
property sets or gets the placeholder attribute of a password field.
The placeholder
attribute sets a short hint text
that describes the expected value of a password field.
placeholder |
Yes | 10.0 | Yes | Yes | Yes |
Return the placeholder property.
var v = passwordObject.placeholder
Set the placeholder property.
passwordObject.placeholder=text
Value | Description |
---|---|
text | Set a short hint text that describes the expected value of the password field |
A String type value representing a short hint text.
The following code shows how to get the placeholder text of a password field.
<!DOCTYPE html>
<html>
<body>
Password: <input type="password" id="myPsw" placeholder="Your password">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from w ww . j a v a2 s . c o m-->
var x = document.getElementById("myPsw").placeholder;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to change the placeholder text of a password field.
<!DOCTYPE html>
<html>
<body>
<!-- ww w . j a va2 s . co m-->
Password: <input type="password" id="myPsw" placeholder="Psw..">
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myPsw").placeholder = "Type your password";
}
</script>
</body>
</html>
The code above is rendered as follows: