Javascript DOM HTML Input Number defaultValue Property set

Introduction

Change the default value of a number field:

document.getElementById("myNumber").defaultValue = "16";

Click the button to change the default value of the number field.

View in separate window

<!DOCTYPE html>
<html>
<body>

Number: <input type="number" id="myNumber" value="2">
<button type="button" onclick="myFunction()">Test</button>
<script>
function myFunction() {//from www  .  j  ava 2s  .com
  document.getElementById("myNumber").defaultValue = "16";
}
</script>

</body>
</html>

The defaultValue property sets or gets the default value of a number field.

The default value is the value specified in the HTML value attribute.

The defaultValue contains the default value, while value contains the current value after some changes have been made.

If there are no changes, defaultValue and value is the same.

The defaultValue property accepts and returns a number type value.




PreviousNext

Related