The placeholder
property sets or gets the placeholder attribute of a text field.
The placeholder
attribute specifies a short hint text
that describes the expected value of a text field.
placeholder |
Yes | 10 | Yes | Yes | Yes |
Return the placeholder property.
var v = textObject.placeholder
Set the placeholder property.
textObject.placeholder=text
Value | Description |
---|---|
text | Specifies a short hint that describes the expected value of the text field |
A String type value representing a short hint that describes the expected value of the text field.
The following code shows how to get the placeholder text of a text field.
<!DOCTYPE html>
<html>
<body>
<!--from w w w. ja v a2 s .c om-->
First Name: <input type="text" id="myText" placeholder="Name">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myText").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 text field.
<!DOCTYPE html>
<html>
<body>
<!--from w w w .j ava2 s . co m-->
First Name: <input type="text" id="myText" placeholder="Name">
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myText").placeholder = "first name here..";
}
</script>
</body>
</html>
The code above is rendered as follows: