Input Text placeholder Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

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

Return Value

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:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials