Javascript examples for DOM HTML Element:Input Text
The placeholder property sets or gets the placeholder attribute of a text field.
Set the placeholder property with the following Values
Value | Description |
---|---|
text | Sets a short hint that describes the expected value of the text field |
A String, representing a short hint that describes the expected value of the text field
The following code shows how to change the placeholder text of a text field:
<!DOCTYPE html> <html> <body> First Name: <input type="text" id="myText" placeholder="Name"> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w w w . ja v a 2s .c o m document.getElementById("myText").placeholder = 'asdf'; document.getElementById("demo").innerHTML = 'changed'; } </script> </body> </html>