Javascript DOM HTML Input Number placeholder Property set

Introduction

Change the placeholder text of a number field:

document.getElementById("myNumber").placeholder = "Amount";

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

View in separate window

<!DOCTYPE html>
<html>
<body>

<input type="number" id="myNumber" placeholder="Quantity">
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {//w w  w .j a v a  2 s  .co  m
  document.getElementById("myNumber").placeholder = "Amount";
}
</script>

</body>
</html>

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

The placeholder attribute stores a hint message.

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

The placeholder property accepts and returns a String type value.




PreviousNext

Related