Javascript DOM HTML Input Text placeholder Property set

Introduction

Change the placeholder text of a text field:

document.getElementById("myText").placeholder = "Type name here..";

Click the button to change the placeholder text of the text field.

View in separate window

<!DOCTYPE html>
<html>
<body>

First Name: <input type="text" id="myText" placeholder="Name">
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {//from ww  w  .jav a2s .c  om
  document.getElementById("myText").placeholder = "Type name here..";
}
</script>

</body>
</html>

The placeholder property sets or gets the placeholder attribute of a text field.

The placeholder attribute sets a short message for the expected value of a text field.

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

The placeholder property accepts and returns a String type value.




PreviousNext

Related