Javascript Reference - HTML DOM Input URL placeholder Property








The placeholder attribute sets a short hint text to explain the expected value of an URL field.

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

Browser Support

placeholder Yes 10.0 Yes Yes Yes

Syntax

Return the placeholder property.

var v = urlObject.placeholder

Set the placeholder property.

urlObject.placeholder=text




Property Values

Value Description
text Set a short hint text that describes the expected value of the URL field

Return Value

A String type value representing a short hint that describes the expected value of the URL field.

Example

The following code shows how to get the placeholder text of a URL field.


<!DOCTYPE html>
<html>
<body>
Homepage: <input type="url" id="myURL" placeholder="Address of web site">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from w w  w .ja v  a  2 s .  co  m-->
    var x = document.getElementById("myURL").placeholder;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to change the placeholder text of a URL field.


<!DOCTYPE html>
<html>
<body>
<!--  w  w  w.  jav a2  s . c  o m-->
Homepage: <input type="url" id="myURL" placeholder="URL">
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    document.getElementById("myURL").placeholder = "Type URL here..";
}
</script>
</body>
</html>

The code above is rendered as follows: