Input Number placeholder Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Number

Description

The placeholder property sets or gets the placeholder attribute of a number field, which provides hint for users.

Set the placeholder property with the following Values

Value Description
text Sets a short hint that describes the expected value of the number field

Return Value

A String, representing a short hint that describes the expected value of the number field

The following code shows how to change the placeholder text of a number field:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<input type="number" id="myNumber" placeholder="Favorite Number">

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from  w  ww. j a  v a 2 s .c o m
    var x = document.getElementById("myNumber").placeholder;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials