Input Password placeholder Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Password

Description

The placeholder property sets or gets the placeholder attribute of a password field, which ets a hint for users.

The short hint is displayed in the password field before the user enters a value.

Set the placeholder property with the following Values

Value Description
text Sets a short hint that describes the expected value of the password field

Return Value

A String, representing a short hint that describes the expected value of the password field

The following code shows how to change the placeholder text of a password field:

Demo Code

ResultView the demo in separate window

<!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() {/*  www.ja  v a 2  s .c  o  m*/
    var x = document.getElementById("myPsw").placeholder;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials